UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

72 lines 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExtractionClient = void 0; const OperationsBase_1 = require("../../common/OperationsBase"); const Errors_1 = require("../../common/Errors"); const EntityListIteratorImpl_1 = require("../../common/iterators/EntityListIteratorImpl"); const IteratorUtil_1 = require("../../common/iterators/IteratorUtil"); class ExtractionClient extends OperationsBase_1.OperationsBase { _baseUrl = `${this.basePath}/datasources/imodel-mappings/extractions`; constructor(basePath) { super(basePath ?? OperationsBase_1.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 Errors_1.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 Errors_1.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_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.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 Errors_1.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 Errors_1.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_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.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, }; })); } } exports.ExtractionClient = ExtractionClient; //# sourceMappingURL=ExtractionClient.js.map