@itwin/insights-client
Version:
Insights client for the iTwin platform
29 lines • 964 B
JavaScript
export async function* flatten(pagedIterator) {
for await (const entityChunk of pagedIterator) {
for (const entity of entityChunk) {
yield entity;
}
}
}
export async function getEntityCollectionPage(nextUrl, getNextBatch) {
const response = await getNextBatch(nextUrl);
// eslint-disable-next-line @typescript-eslint/naming-convention
const nextLink = response._links.next;
return {
entities: response.values,
next: nextLink ? async () => getEntityCollectionPage(nextLink.href, getNextBatch) : undefined,
};
}
/**
* Loads all entities from an iterator into an array.
* @param {AsyncIterableIterator<TEntity>} iterator entity iterator.
* @returns {Promise<TEntity[]>} entity array.
*/
export async function toArray(iterator) {
const result = [];
for await (const entity of iterator) {
result.push(entity);
}
return result;
}
//# sourceMappingURL=IteratorUtil.js.map