Skip to content

Commit 23c194b

Browse files
feat(pagination): avoid fetching when has_more: false (#1305)
1 parent f446412 commit 23c194b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: .stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 69
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-7c699d4503077d06a4a44f52c0c1f902d19a87c766b8be75b97c8dfd484ad4aa.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-dfb00c627f58e5180af7a9b29ed2f2aa0764a3b9daa6a32a1cc45bc8e48dfe15.yml

Diff for: src/pagination.ts

+13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item>
4343

4444
export interface CursorPageResponse<Item> {
4545
data: Array<Item>;
46+
47+
has_more: boolean;
4648
}
4749

4850
export interface CursorPageParams {
@@ -57,6 +59,8 @@ export class CursorPage<Item extends { id: string }>
5759
{
5860
data: Array<Item>;
5961

62+
has_more: boolean;
63+
6064
constructor(
6165
client: APIClient,
6266
response: Response,
@@ -66,12 +70,21 @@ export class CursorPage<Item extends { id: string }>
6670
super(client, response, body, options);
6771

6872
this.data = body.data || [];
73+
this.has_more = body.has_more || false;
6974
}
7075

7176
getPaginatedItems(): Item[] {
7277
return this.data ?? [];
7378
}
7479

80+
override hasNextPage() {
81+
if (this.has_more === false) {
82+
return false;
83+
}
84+
85+
return super.hasNextPage();
86+
}
87+
7588
// @deprecated Please use `nextPageInfo()` instead
7689
nextPageParams(): Partial<CursorPageParams> | null {
7790
const info = this.nextPageInfo();

0 commit comments

Comments
 (0)