Skip to content

Commit 87d26db

Browse files
stainless-botRobertCraigie
authored andcommitted
feat(pagination): avoid fetching when has_more: false
chore: unknown commit message
1 parent 4cec09d commit 87d26db

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
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

src/pagination.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item>
145145

146146
export interface CursorPageResponse<Item> {
147147
data: Array<Item>;
148+
149+
has_more: boolean;
148150
}
149151

150152
export interface CursorPageParams {
@@ -159,6 +161,8 @@ export class CursorPage<Item extends { id: string }>
159161
{
160162
data: Array<Item>;
161163

164+
has_more: boolean;
165+
162166
constructor(
163167
client: OpenAI,
164168
response: Response,
@@ -168,12 +172,21 @@ export class CursorPage<Item extends { id: string }>
168172
super(client, response, body, options);
169173

170174
this.data = body.data || [];
175+
this.has_more = body.has_more || false;
171176
}
172177

173178
getPaginatedItems(): Item[] {
174179
return this.data ?? [];
175180
}
176181

182+
override hasNextPage() {
183+
if (this.has_more === false) {
184+
return false;
185+
}
186+
187+
return super.hasNextPage();
188+
}
189+
177190
nextPageRequestOptions(): PageRequestOptions | null {
178191
const data = this.getPaginatedItems();
179192
const id = data[data.length - 1]?.id;

0 commit comments

Comments
 (0)