@@ -6,7 +6,7 @@ import { defaultParseResponse } from '../internal/parse';
66import { type Kernel } from '../client' ;
77import { APIPromise } from './api-promise' ;
88import { type APIResponseProps } from '../internal/parse' ;
9- import { maybeObj } from '../internal/utils/values' ;
9+ import { maybeCoerceBoolean , maybeCoerceInteger , maybeObj } from '../internal/utils/values' ;
1010
1111export type PageRequestOptions = Pick < FinalRequestOptions , 'query' | 'headers' | 'body' | 'path' | 'method' > ;
1212
@@ -118,6 +118,10 @@ export interface OffsetPaginationParams {
118118export class OffsetPagination < Item > extends AbstractPage < Item > {
119119 items : Array < Item > ;
120120
121+ has_more : boolean | null ;
122+
123+ next_offset : number | null ;
124+
121125 constructor (
122126 client : Kernel ,
123127 response : Response ,
@@ -127,14 +131,24 @@ export class OffsetPagination<Item> extends AbstractPage<Item> {
127131 super ( client , response , body , options ) ;
128132
129133 this . items = body || [ ] ;
134+ this . has_more = maybeCoerceBoolean ( this . response . headers . get ( 'x-has-more' ) ) ?? null ;
135+ this . next_offset = maybeCoerceInteger ( this . response . headers . get ( 'x-next-offset' ) ) ?? null ;
130136 }
131137
132138 getPaginatedItems ( ) : Item [ ] {
133139 return this . items ?? [ ] ;
134140 }
135141
142+ override hasNextPage ( ) : boolean {
143+ if ( this . has_more === false ) {
144+ return false ;
145+ }
146+
147+ return super . hasNextPage ( ) ;
148+ }
149+
136150 nextPageRequestOptions ( ) : PageRequestOptions | null {
137- const offset = ( this . options . query as OffsetPaginationParams ) . offset ?? 0 ;
151+ const offset = this . next_offset ;
138152 if ( ! offset ) {
139153 return null ;
140154 }
0 commit comments