@@ -5,7 +5,7 @@ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from
5
5
export interface PageResponse < Item > {
6
6
data : Array < Item > ;
7
7
8
- object : 'list' ;
8
+ object : string ;
9
9
}
10
10
11
11
/**
@@ -14,17 +14,17 @@ export interface PageResponse<Item> {
14
14
export class Page < Item > extends AbstractPage < Item > implements PageResponse < Item > {
15
15
data : Array < Item > ;
16
16
17
- object : 'list' ;
17
+ object : string ;
18
18
19
19
constructor ( client : APIClient , response : Response , body : PageResponse < Item > , options : FinalRequestOptions ) {
20
20
super ( client , response , body , options ) ;
21
21
22
- this . data = body . data ;
22
+ this . data = body . data || [ ] ;
23
23
this . object = body . object ;
24
24
}
25
25
26
26
getPaginatedItems ( ) : Item [ ] {
27
- return this . data ;
27
+ return this . data ?? [ ] ;
28
28
}
29
29
30
30
// @deprecated Please use `nextPageInfo()` instead
@@ -46,14 +46,8 @@ export interface CursorPageResponse<Item> {
46
46
}
47
47
48
48
export interface CursorPageParams {
49
- /**
50
- * Identifier for the last job from the previous pagination request.
51
- */
52
49
after ?: string ;
53
50
54
- /**
55
- * Number of fine-tuning jobs to retrieve.
56
- */
57
51
limit ?: number ;
58
52
}
59
53
@@ -71,11 +65,11 @@ export class CursorPage<Item extends { id: string }>
71
65
) {
72
66
super ( client , response , body , options ) ;
73
67
74
- this . data = body . data ;
68
+ this . data = body . data || [ ] ;
75
69
}
76
70
77
71
getPaginatedItems ( ) : Item [ ] {
78
- return this . data ;
72
+ return this . data ?? [ ] ;
79
73
}
80
74
81
75
// @deprecated Please use `nextPageInfo()` instead
@@ -89,12 +83,16 @@ export class CursorPage<Item extends { id: string }>
89
83
}
90
84
91
85
nextPageInfo ( ) : PageInfo | null {
92
- if ( ! this . data ?. length ) {
86
+ const data = this . getPaginatedItems ( ) ;
87
+ if ( ! data . length ) {
88
+ return null ;
89
+ }
90
+
91
+ const id = data [ data . length - 1 ] ?. id ;
92
+ if ( ! id ) {
93
93
return null ;
94
94
}
95
95
96
- const next = this . data [ this . data . length - 1 ] ?. id ;
97
- if ( ! next ) return null ;
98
- return { params : { after : next } } ;
96
+ return { params : { after : id } } ;
99
97
}
100
98
}
0 commit comments