@itwin/insights-client
Version:
Insights client for the iTwin platform
98 lines • 5.33 kB
JavaScript
;
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); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestIModelRetriever = void 0;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const inversify_1 = require("inversify");
const IteratorUtil_1 = require("../../../../../common/iterators/IteratorUtil");
const CommonTestUtils_1 = require("../../CommonTestUtils");
const TestAuthorizationProvider_1 = require("../auth/TestAuthorizationProvider");
const TestITwinProvider_1 = require("../itwin/TestITwinProvider");
const TestIModelFileProvider_1 = require("./TestIModelFileProvider");
const TestIModelsClient_1 = require("./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 (0, IteratorUtil_1.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 (0, IteratorUtil_1.toArray)(this._iModelsClient.changesets.getMinimalList(getChangesetListParams));
if (changesets.length === 0)
throw new CommonTestUtils_1.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 (0, IteratorUtil_1.toArray)(this._iModelsClient.briefcases.getRepresentationList(getBriefcaseListParams));
if (briefcases.length !== 1)
throw new CommonTestUtils_1.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 (0, IteratorUtil_1.toArray)(this._iModelsClient.locks.getList(getLockListParams));
if (locks.length !== 1) {
throw new CommonTestUtils_1.TestSetupError(`${locks.length} is an unexpected lock count for reusable test iModel.`);
}
return locks[0];
}
};
exports.TestIModelRetriever = TestIModelRetriever;
exports.TestIModelRetriever = TestIModelRetriever = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(TestIModelsClient_1.TestIModelsClient)),
__param(1, (0, inversify_1.inject)(TestAuthorizationProvider_1.TestAuthorizationProvider)),
__param(2, (0, inversify_1.inject)(TestITwinProvider_1.TestITwinProvider)),
__param(3, (0, inversify_1.inject)(TestIModelFileProvider_1.TestIModelFileProvider))
], TestIModelRetriever);
//# sourceMappingURL=TestIModelRetriever.js.map