Repository navigation
Expand file tree
/
Copy pathpagination.ts
More file actions
77 lines (63 loc) · 1.52 KB
/
Copy pathpagination.ts
File metadata and controls
77 lines (63 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const PAGINATION_TYPES = ['cursor', 'offset'] as const;
export type PaginationType = (typeof PAGINATION_TYPES)[number];
type PaginationRequestBase = {
/**
* The type of pagination to use
*/
type: PaginationType;
/**
* The number of items to return per page
* @example 10
*/
limit?: number;
};
export type CursorBasedPaginationRequest = PaginationRequestBase & {
type: 'cursor';
/**
* The cursor for the next page of results
* Not required for the first page
* @example "eyJ2IjoxLCJwIjoxLCJzIjoxfQ=="
*/
cursor?: string;
};
export type OffsetBasedPaginationRequest = PaginationRequestBase & {
type: 'offset';
/**
* The offset for the next page of results
* @example 0
*/
offset?: number;
};
export type PaginationRequest =
| CursorBasedPaginationRequest
| OffsetBasedPaginationRequest;
type PaginationResponseBase = {
/**
* The type of pagination used
*/
type: PaginationType;
/**
* The total number of items available
* @example 100
*/
totalItems: number;
/**
* The total number of pages available
* @example 10
*/
totalPages: number;
};
export type CursorBasedPaginationResponse = PaginationResponseBase & {
type: 'cursor';
/**
* The cursor for the next page of results
* @example "eyJ2IjoxLCJwIjoxLCJzIjoxfQ=="
*/
cursor?: string;
};
export type OffsetBasedPaginationResponse = PaginationResponseBase & {
type: 'offset';
};
export type PaginationResponse =
| CursorBasedPaginationResponse
| OffsetBasedPaginationResponse;