@itwin/insights-client
Version:
Insights client for the iTwin platform
68 lines • 3.65 kB
JavaScript
import { GROUPING_AND_MAPPING_BASE_PATH, OperationsBase } from "../../common/OperationsBase";
import { RequiredError } from "../../common/Errors";
import { EntityListIteratorImpl } from "../../common/iterators/EntityListIteratorImpl";
import { getEntityCollectionPage } from "../../common/iterators/IteratorUtil";
export class ExtractionClient extends OperationsBase {
_baseUrl = `${this.basePath}/datasources/imodel-mappings/extractions`;
constructor(basePath) {
super(basePath ?? GROUPING_AND_MAPPING_BASE_PATH);
}
async runExtraction(accessToken, extractionRequestDetails) {
const requestOptions = this.createRequest("POST", accessToken, JSON.stringify(extractionRequestDetails));
return (await this.fetchJSON(this._baseUrl, requestOptions)).extraction;
}
async getExtractionStatus(accessToken, extractionId) {
const url = `${this._baseUrl}/${encodeURIComponent(extractionId)}`;
const requestOptions = this.createRequest("GET", accessToken);
return (await this.fetchJSON(url, requestOptions)).extraction;
}
async getIModelExtractions(accessToken, iModelId, top) {
if (!this.topIsValid(top)) {
throw new RequiredError("top", "Parameter top was outside of the valid range [1-1000].");
}
const url = `${this._baseUrl}?iModelId=${iModelId}${top ? `&$top=${top}` : ``}`;
const requestOptions = this.createRequest("GET", accessToken);
const response = await this.fetchJSON(url, requestOptions);
return response;
}
getIModelExtractionsIterator(accessToken, iModelId, top) {
if (!this.topIsValid(top)) {
throw new RequiredError("top", "Parameter top was outside of the valid range [1-1000].");
}
const url = `${this._baseUrl}?iModelId=${iModelId}${top ? `&$top=${top}` : ``}`;
const requestOptions = this.createRequest("GET", accessToken);
return new EntityListIteratorImpl(async () => getEntityCollectionPage(url, async (nextUrl) => {
const response = await this.fetchJSON(nextUrl, requestOptions);
return {
values: response.extractions,
// eslint-disable-next-line @typescript-eslint/naming-convention
_links: response._links,
};
}));
}
async getExtractionLogs(accessToken, extractionId, top) {
if (!this.topIsValid(top)) {
throw new RequiredError("top", "Parameter top was outside of the valid range [1-1000].");
}
const url = `${this._baseUrl}/${encodeURIComponent(extractionId)}/logs${top ? `?$top=${top}` : ``}`;
const requestOptions = this.createRequest("GET", accessToken);
const response = await this.fetchJSON(url, requestOptions);
return response;
}
getExtractionLogsIterator(accessToken, extractionId, top) {
if (!this.topIsValid(top)) {
throw new RequiredError("top", "Parameter top was outside of the valid range [1-1000].");
}
const url = `${this._baseUrl}/${encodeURIComponent(extractionId)}/logs${top ? `?$top=${top}` : ``}`;
const requestOptions = this.createRequest("GET", accessToken);
return new EntityListIteratorImpl(async () => getEntityCollectionPage(url, async (nextUrl) => {
const response = await this.fetchJSON(nextUrl, requestOptions);
return {
values: response.logs,
// eslint-disable-next-line @typescript-eslint/naming-convention
_links: response._links,
};
}));
}
}
//# sourceMappingURL=ExtractionClient.js.map