MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / OffsetLimitPage

Class OffsetLimitPage

packages/core/src/v3/apiClient/pagination.ts:97–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97export class OffsetLimitPage<Item>
98 implements OffsetLimitPageResponse<Item>, Page<Item>, AsyncIterable<Item>
99{
100 data: Array<Item>;
101 pagination: { currentPage: number; totalPages: number; count: number };
102
103 constructor(
104 data: Array<Item>,
105 pagination: { currentPage: number; totalPages: number; count: number },
106 private pageFetcher: (
107 params: Omit<OffsetLimitPageParams, "limit">
108 ) => Promise<OffsetLimitPage<Item>>
109 ) {
110 this.data = data;
111 this.pagination = pagination;
112 }
113
114 getPaginatedItems(): Item[] {
115 return this.data ?? [];
116 }
117
118 hasNextPage(): boolean {
119 return this.pagination.currentPage < this.pagination.totalPages;
120 }
121
122 hasPreviousPage(): boolean {
123 return this.pagination.currentPage > 1;
124 }
125
126 getNextPage(): Promise<OffsetLimitPage<Item>> {
127 if (!this.hasNextPage()) {
128 throw new Error("No next page available");
129 }
130
131 return this.pageFetcher({
132 page: this.pagination.currentPage + 1,
133 });
134 }
135
136 getPreviousPage(): Promise<OffsetLimitPage<Item>> {
137 if (!this.hasPreviousPage()) {
138 throw new Error("No previous page available");
139 }
140
141 return this.pageFetcher({
142 page: this.pagination.currentPage - 1,
143 });
144 }
145
146 async *iterPages() {
147 // eslint-disable-next-line @typescript-eslint/no-this-alias
148 let page: OffsetLimitPage<Item> = this;
149 yield page;
150 while (page.hasNextPage()) {
151 page = await page.getNextPage();
152 yield page;
153 }
154 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…