Paginate through a list of results.
(
task: (key: string) => Promise<Page<T>>,
key: IntegrationTaskKey,
counter: number = 0
)
| 112 | |
| 113 | /** Paginate through a list of results. */ |
| 114 | async *paginate<T>( |
| 115 | task: (key: string) => Promise<Page<T>>, |
| 116 | key: IntegrationTaskKey, |
| 117 | counter: number = 0 |
| 118 | ): AsyncGenerator<T[]> { |
| 119 | const boundTask = task.bind(this as any); |
| 120 | |
| 121 | const page = await boundTask(`${key}-${counter}`); |
| 122 | yield page.results; |
| 123 | |
| 124 | if (page.next) { |
| 125 | const nextStep = counter++; |
| 126 | |
| 127 | const nextPage = () => { |
| 128 | return this.request<Page<T>>(`${key}-${nextStep}`, { |
| 129 | route: page.next!, |
| 130 | options: { method: "GET" }, |
| 131 | }); |
| 132 | }; |
| 133 | |
| 134 | yield* this.paginate(nextPage, key, nextStep); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /** Auto-paginate and return all results. */ |
| 139 | async getAll<T>( |
no outgoing calls
no test coverage detected