(
path: CloudGetRequestPath,
get: (path: CloudGetRequestPath, query?: Record<string, string>) => Promise<CloudPaginatedResponse<T>>
)
| 171 | * expects `url` to be of type `CloudGetRequestPath`. See example. |
| 172 | **/ |
| 173 | const getPaginatedCloud = async <T>( |
| 174 | path: CloudGetRequestPath, |
| 175 | get: (path: CloudGetRequestPath, query?: Record<string, string>) => Promise<CloudPaginatedResponse<T>> |
| 176 | ): Promise<T[]> => { |
| 177 | const results: T[] = []; |
| 178 | let nextPath = path; |
| 179 | let nextQuery = undefined; |
| 180 | |
| 181 | while (true) { |
| 182 | const response = await get(nextPath, nextQuery); |
| 183 | |
| 184 | if (!response.values || response.values.length === 0) { |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | results.push(...response.values); |
| 189 | |
| 190 | if (!response.next) { |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | const parsedUrl = parseUrl(response.next); |
| 195 | nextPath = parsedUrl.path as CloudGetRequestPath; |
| 196 | nextQuery = parsedUrl.query; |
| 197 | } |
| 198 | return results; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Parse the url into a path and query parameters to be used with the api client (openapi-fetch) |
no test coverage detected