UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

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