UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

95 lines 4.84 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { inject, injectable } from "inversify"; import { toArray } from "../../../../../common/iterators/IteratorUtil"; import { TestSetupError } from "../../CommonTestUtils"; import { TestAuthorizationProvider } from "../auth/TestAuthorizationProvider"; import { TestITwinProvider } from "../itwin/TestITwinProvider"; import { TestIModelFileProvider } from "./TestIModelFileProvider"; import { TestIModelsClient } from "./TestIModelsClient"; let TestIModelRetriever = class TestIModelRetriever { constructor(_iModelsClient, _testAuthorizationProvider, _testProjectProvider, _testIModelFileProvider) { this._iModelsClient = _iModelsClient; this._testAuthorizationProvider = _testAuthorizationProvider; this._testProjectProvider = _testProjectProvider; this._testIModelFileProvider = _testIModelFileProvider; } async findIModelByName(iModelName) { const iTwinId = await this._testProjectProvider.getOrCreate(); const iModelIterator = this._iModelsClient.iModels.getRepresentationList({ authorization: this._testAuthorizationProvider.getAdmin1Authorization(), urlParams: { iTwinId, name: iModelName, }, }); const iModels = await toArray(iModelIterator); return iModels.length === 0 ? undefined : iModels[0]; } async queryRelatedData(iModel) { const briefcase = await this.queryAndValidateBriefcase(iModel.id); const lock = await this.queryAndValidateLock(iModel.id); const changesetIds = await this.getChangesetIds(iModel.id); return { id: iModel.id, changesetId: changesetIds[changesetIds.length - 1], name: iModel.name, description: iModel.description ?? "", briefcase, lock, }; } async getChangesetIds(iModelId) { const getChangesetListParams = { authorization: this._testAuthorizationProvider.getAdmin1Authorization(), iModelId, }; const changesets = await toArray(this._iModelsClient.changesets.getMinimalList(getChangesetListParams)); if (changesets.length === 0) throw new TestSetupError("No changesets found for reusable test IModel."); return changesets.map((x) => (x.id)); } async queryAndValidateBriefcase(iModelId) { const getBriefcaseListParams = { authorization: this._testAuthorizationProvider.getAdmin1Authorization(), iModelId, }; const briefcases = await toArray(this._iModelsClient.briefcases.getRepresentationList(getBriefcaseListParams)); if (briefcases.length !== 1) throw new TestSetupError(`${briefcases.length} is an unexpected briefcase count for reusable test IModel.`); return { id: briefcases[0].briefcaseId, deviceName: briefcases[0].deviceName ?? "" }; } async queryAndValidateLock(iModelId) { const getLockListParams = { authorization: this._testAuthorizationProvider.getAdmin1Authorization(), iModelId, }; const locks = await toArray(this._iModelsClient.locks.getList(getLockListParams)); if (locks.length !== 1) { throw new TestSetupError(`${locks.length} is an unexpected lock count for reusable test iModel.`); } return locks[0]; } }; TestIModelRetriever = __decorate([ injectable(), __param(0, inject(TestIModelsClient)), __param(1, inject(TestAuthorizationProvider)), __param(2, inject(TestITwinProvider)), __param(3, inject(TestIModelFileProvider)) ], TestIModelRetriever); export { TestIModelRetriever }; //# sourceMappingURL=TestIModelRetriever.js.map