UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

93 lines 5.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MappingsClient = 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 MappingsClient extends OperationsBase_1.OperationsBase { constructor(basePath) { super(basePath ?? OperationsBase_1.GROUPING_AND_MAPPING_BASE_PATH); this._baseUrl = `${this.basePath}/datasources/imodel-mappings`; } async createMapping(accessToken, mappingCreate) { if (!this.isSimpleIdentifier(mappingCreate.mappingName)) { throw new Errors_1.RequiredError("mappingName", "Required field mappingName was missing or invalid."); } const requestOptions = this.createRequest("POST", accessToken, JSON.stringify(mappingCreate)); return (await this.fetchJSON(this._baseUrl, requestOptions)).mapping; } async updateMapping(accessToken, mappingId, mappingUpdate) { if (mappingUpdate.description == null && mappingUpdate.extractionEnabled == null && mappingUpdate.mappingName == null) { throw new Errors_1.RequiredError("mapping", "All properties of mapping were missing."); } if (mappingUpdate.mappingName != null && !this.isSimpleIdentifier(mappingUpdate.mappingName)) { throw new Errors_1.RequiredError("mappingName", "Required field mappingName was invalid."); } const mappingUrl = `${this._baseUrl}/${encodeURIComponent(mappingId)}`; const requestOptions = this.createRequest("PATCH", accessToken, JSON.stringify(mappingUpdate)); return (await this.fetchJSON(mappingUrl, requestOptions)).mapping; } async deleteMapping(accessToken, mappingId) { const mappingUrl = `${this._baseUrl}/${encodeURIComponent(mappingId)}`; const requestOptions = this.createRequest("DELETE", accessToken); return this.fetchJSON(mappingUrl, requestOptions); } async getMapping(accessToken, mappingId) { const mappingUrl = `${this._baseUrl}/${encodeURIComponent(mappingId)}`; const requestOptions = this.createRequest("GET", accessToken); return (await this.fetchJSON(mappingUrl, requestOptions)).mapping; } getMappingsIterator(accessToken, iModelId, top) { if (!this.topIsValid(top)) { throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000]."); } const baseUrl = `${this._baseUrl}?iModelId=${encodeURIComponent(iModelId)}`; const url = `${baseUrl}${top ? `&$top=${top}` : ""}`; const request = this.createRequest("GET", accessToken); return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.getEntityCollectionPage)(url, async (nextUrl) => { const response = await this.fetchJSON(nextUrl, request); return { values: response.mappings, _links: response._links, }; })); } async getMappings(accessToken, iModelId, top) { if (!this.topIsValid(top)) { throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000]."); } const baseUrl = `${this._baseUrl}?iModelId=${encodeURIComponent(iModelId)}`; const url = `${baseUrl}${top ? `&$top=${top}` : ""}`; const request = this.createRequest("GET", accessToken); const response = await this.fetchJSON(url, request); return response; } getMappingExtractionsIterator(accessToken, mappingId, top) { if (!this.topIsValid(top)) { throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000]."); } const baseUrl = `${this._baseUrl}/${encodeURIComponent(mappingId)}/extractions`; const url = `${baseUrl}${top ? `?$top=${top}` : ""}`; const request = this.createRequest("GET", accessToken); return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.getEntityCollectionPage)(url, async (nextUrl) => { const response = await this.fetchJSON(nextUrl, request); return { values: response.extractions, _links: response._links, }; })); } async getMappingExtractions(accessToken, mappingId, top) { if (!this.topIsValid(top)) { throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000]."); } const baseUrl = `${this._baseUrl}/${encodeURIComponent(mappingId)}/extractions`; const url = `${baseUrl}${top ? `?$top=${top}` : ""}`; const request = this.createRequest("GET", accessToken); const response = await this.fetchJSON(url, request); return response; } } exports.MappingsClient = MappingsClient; //# sourceMappingURL=MappingsClient.js.map