UNPKG

@itwin/insights-client

Version:

Insights client for the iTwin platform

124 lines 5.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 { LockLevel } from "@itwin/imodels-client-authoring"; import { TestITwinProvider } from "../itwin/TestITwinProvider"; import { TestIModelFileProvider } from "./TestIModelFileProvider"; import { TestIModelsClient } from "./TestIModelsClient"; import { TestAuthorizationProvider } from "../auth/TestAuthorizationProvider"; let TestIModelCreator = class TestIModelCreator { constructor(_iModelsClient, _testAuthorizationProvider, _testProjectProvider, _testIModelFileProvider) { this._iModelsClient = _iModelsClient; this._testAuthorizationProvider = _testAuthorizationProvider; this._testProjectProvider = _testProjectProvider; this._testIModelFileProvider = _testIModelFileProvider; this._iModelDescription = "Some description"; this._briefcaseDeviceName = "Some device name"; } async createEmpty(iModelName) { const iTwinId = await this._testProjectProvider.getOrCreate(); const iModel = await this._iModelsClient.iModels.createEmpty({ authorization: this._testAuthorizationProvider.getAdmin1Authorization(), iModelProperties: { iTwinId, name: iModelName, description: this._iModelDescription, }, }); return { id: iModel.id, name: iModel.name, description: iModel.description ?? "", }; } async createEmptyAndUploadChangesets(iModelName) { const iModel = await this.createEmpty(iModelName); const briefcase = await this.acquireBriefcase(iModel.id); await this.uploadChangesets(iModel.id, briefcase.id); return iModel; } async createReusable(iModelName) { const iModel = await this.createEmpty(iModelName); const briefcase = await this.acquireBriefcase(iModel.id); const changesets = await this.uploadChangesets(iModel.id, briefcase.id); const lock = await this.createLockOnReusableIModel(iModel.id, briefcase.id); return { ...iModel, changesetId: changesets[changesets.length - 1], briefcase, lock, }; } async createLockOnReusableIModel(iModelId, briefcaseId) { const testIModelLocks = [ { lockLevel: LockLevel.Exclusive, objectIds: ["0x1", "0xa"], }, { lockLevel: LockLevel.Shared, objectIds: ["0x2", "0xb"], }, ]; const acquiredLocks = await this._iModelsClient.locks.update({ authorization: this._testAuthorizationProvider.getAdmin1Authorization(), iModelId, briefcaseId, lockedObjects: testIModelLocks, }); return acquiredLocks; } async uploadChangesets(iModelId, briefcaseId) { for (let i = 0; i < this._testIModelFileProvider.changesets.length; i++) { await this._iModelsClient.changesets.create({ authorization: this._testAuthorizationProvider.getAdmin1Authorization(), iModelId, changesetProperties: { briefcaseId, description: this._testIModelFileProvider.changesets[i].description, containingChanges: this._testIModelFileProvider.changesets[i].containingChanges, id: this._testIModelFileProvider.changesets[i].id, parentId: i === 0 ? undefined : this._testIModelFileProvider.changesets[i - 1].id, synchronizationInfo: this._testIModelFileProvider.changesets[i].synchronizationInfo, filePath: this._testIModelFileProvider.changesets[i].filePath, }, }); } return this._testIModelFileProvider.changesets.map((x) => (x.id)); } async acquireBriefcase(iModelId) { const briefcase = await this._iModelsClient.briefcases.acquire({ authorization: this._testAuthorizationProvider.getAdmin1Authorization(), iModelId, briefcaseProperties: { deviceName: this._briefcaseDeviceName, }, }); return { id: briefcase.briefcaseId, deviceName: briefcase.deviceName ?? "", }; } }; TestIModelCreator = __decorate([ injectable(), __param(0, inject(TestIModelsClient)), __param(1, inject(TestAuthorizationProvider)), __param(2, inject(TestITwinProvider)), __param(3, inject(TestIModelFileProvider)) ], TestIModelCreator); export { TestIModelCreator }; //# sourceMappingURL=TestIModelCreator.js.map