@itwin/insights-client
Version:
Insights client for the iTwin platform
127 lines • 6.25 kB
JavaScript
"use strict";
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.TestIModelCreator = 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 imodels_client_authoring_1 = require("@itwin/imodels-client-authoring");
const TestITwinProvider_1 = require("../itwin/TestITwinProvider");
const TestIModelFileProvider_1 = require("./TestIModelFileProvider");
const TestIModelsClient_1 = require("./TestIModelsClient");
const TestAuthorizationProvider_1 = require("../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: imodels_client_authoring_1.LockLevel.Exclusive,
objectIds: ["0x1", "0xa"],
},
{
lockLevel: imodels_client_authoring_1.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 ?? "",
};
}
};
exports.TestIModelCreator = TestIModelCreator;
exports.TestIModelCreator = TestIModelCreator = __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))
], TestIModelCreator);
//# sourceMappingURL=TestIModelCreator.js.map