// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core'; export interface V4PagePaginationResponse { result: V4PagePaginationResponse.Result; result_info: V4PagePaginationResponse.ResultInfo; } export namespace V4PagePaginationResponse { export interface Result { items?: Array; } export interface ResultInfo { page?: number; per_page?: number; } } export interface V4PagePaginationParams { page?: number; per_page?: number; } export class V4PagePagination extends AbstractPage implements V4PagePaginationResponse { result: V4PagePaginationResponse.Result; result_info: V4PagePaginationResponse.ResultInfo; constructor( client: APIClient, response: Response, body: V4PagePaginationResponse, options: FinalRequestOptions, ) { super(client, response, body, options); this.result = body.result || {}; this.result_info = body.result_info || {}; } getPaginatedItems(): Item[] { return this.result?.items ?? []; } // @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 query = this.options.query as V4PagePaginationParams; const currentPage = query?.page ?? 1; return { params: { page: currentPage + 1 } }; } } export interface V4PagePaginationArrayResponse { result: Array; result_info: V4PagePaginationArrayResponse.ResultInfo; } export namespace V4PagePaginationArrayResponse { export interface ResultInfo { page?: number; per_page?: number; } } export interface V4PagePaginationArrayParams { page?: number; per_page?: number; } export class V4PagePaginationArray extends AbstractPage implements V4PagePaginationArrayResponse { result: Array; result_info: V4PagePaginationArrayResponse.ResultInfo; constructor( client: APIClient, response: Response, body: V4PagePaginationArrayResponse, options: FinalRequestOptions, ) { super(client, response, body, options); this.result = body.result || []; this.result_info = body.result_info || {}; } getPaginatedItems(): Item[] { return this.result ?? []; } // @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 query = this.options.query as V4PagePaginationArrayParams; const currentPage = query?.page ?? 1; return { params: { page: currentPage + 1 } }; } } export interface CursorPaginationResponse { result: Array; result_info: CursorPaginationResponse.ResultInfo; } export namespace CursorPaginationResponse { export interface ResultInfo { count?: number; cursor?: string; per_page?: number; } } export interface CursorPaginationParams { per_page?: number; cursor?: string; } export class CursorPagination extends AbstractPage implements CursorPaginationResponse { result: Array; result_info: CursorPaginationResponse.ResultInfo; constructor( client: APIClient, response: Response, body: CursorPaginationResponse, options: FinalRequestOptions, ) { super(client, response, body, options); this.result = body.result || []; this.result_info = body.result_info || {}; } getPaginatedItems(): Item[] { return this.result ?? []; } // @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 cursor = this.result_info?.cursor; if (!cursor) { return null; } return { params: { cursor, }, }; } } export interface CursorLimitPaginationResponse { result: Array; result_info: CursorLimitPaginationResponse.ResultInfo; } export namespace CursorLimitPaginationResponse { export interface ResultInfo { count?: number; cursor?: string; per_page?: number; } } export interface CursorLimitPaginationParams { limit?: number; cursor?: string; } export class CursorLimitPagination extends AbstractPage implements CursorLimitPaginationResponse { result: Array; result_info: CursorLimitPaginationResponse.ResultInfo; constructor( client: APIClient, response: Response, body: CursorLimitPaginationResponse, options: FinalRequestOptions, ) { super(client, response, body, options); this.result = body.result || []; this.result_info = body.result_info || {}; } getPaginatedItems(): Item[] { return this.result ?? []; } // @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 cursor = this.result_info?.cursor; if (!cursor) { return null; } return { params: { cursor, }, }; } } export interface SinglePageResponse { result: Array; } export class SinglePage extends AbstractPage implements SinglePageResponse { result: Array; constructor( client: APIClient, response: Response, body: SinglePageResponse, options: FinalRequestOptions, ) { super(client, response, body, options); this.result = body.result || []; } getPaginatedItems(): Item[] { return this.result ?? []; } // @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; } }