MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / getPaginatedCloud

Function getPaginatedCloud

packages/backend/src/bitbucket.ts:173–199  ·  view source on GitHub ↗
(
    path: CloudGetRequestPath,
    get: (path: CloudGetRequestPath, query?: Record<string, string>) => Promise<CloudPaginatedResponse<T>>
)

Source from the content-addressed store, hash-verified

171* expects `url` to be of type `CloudGetRequestPath`. See example.
172**/
173const 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)

Calls 1

parseUrlFunction · 0.85

Tested by

no test coverage detected