UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

34 lines 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.flatten = flatten; exports.getEntityCollectionPage = getEntityCollectionPage; exports.toArray = toArray; async function* flatten(pagedIterator) { for await (const entityChunk of pagedIterator) { for (const entity of entityChunk) { yield entity; } } } 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. */ async function toArray(iterator) { const result = []; for await (const entity of iterator) { result.push(entity); } return result; } //# sourceMappingURL=IteratorUtil.js.map