Skip to content

Commit

Permalink
fix(pagination): correct type annotation object field (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Dec 20, 2023
1 parent eb6ceeb commit 4066eda
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from
export interface PageResponse<Item> {
data: Array<Item>;

object: 'list';
object: string;
}

/**
Expand All @@ -14,17 +14,17 @@ export interface PageResponse<Item> {
export class Page<Item> extends AbstractPage<Item> implements PageResponse<Item> {
data: Array<Item>;

object: 'list';
object: string;

constructor(client: APIClient, response: Response, body: PageResponse<Item>, options: FinalRequestOptions) {
super(client, response, body, options);

this.data = body.data;
this.data = body.data || [];
this.object = body.object;
}

getPaginatedItems(): Item[] {
return this.data;
return this.data ?? [];
}

// @deprecated Please use `nextPageInfo()` instead
Expand All @@ -46,14 +46,8 @@ export interface CursorPageResponse<Item> {
}

export interface CursorPageParams {
/**
* Identifier for the last job from the previous pagination request.
*/
after?: string;

/**
* Number of fine-tuning jobs to retrieve.
*/
limit?: number;
}

Expand All @@ -71,11 +65,11 @@ export class CursorPage<Item extends { id: string }>
) {
super(client, response, body, options);

this.data = body.data;
this.data = body.data || [];
}

getPaginatedItems(): Item[] {
return this.data;
return this.data ?? [];
}

// @deprecated Please use `nextPageInfo()` instead
Expand All @@ -89,12 +83,16 @@ export class CursorPage<Item extends { id: string }>
}

nextPageInfo(): PageInfo | null {
if (!this.data?.length) {
const data = this.getPaginatedItems();
if (!data.length) {
return null;
}

const id = data[data.length - 1]?.id;
if (!id) {
return null;
}

const next = this.data[this.data.length - 1]?.id;
if (!next) return null;
return { params: { after: next } };
return { params: { after: id } };
}
}

0 comments on commit 4066eda

Please sign in to comment.