UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

89 lines 4.81 kB
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 MappingsClient extends OperationsBase { constructor(basePath) { super(basePath ?? GROUPING_AND_MAPPING_BASE_PATH); this._baseUrl = `${this.basePath}/datasources/imodel-mappings`; } async createMapping(accessToken, mappingCreate) { if (!this.isSimpleIdentifier(mappingCreate.mappingName)) { throw new 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 RequiredError("mapping", "All properties of mapping were missing."); } if (mappingUpdate.mappingName != null && !this.isSimpleIdentifier(mappingUpdate.mappingName)) { throw new 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 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(async () => 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 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 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(async () => 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 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; } } //# sourceMappingURL=MappingsClient.js.map