@itwin/clash-detection-client
Version:
Clash Detection client for the iTwin platform
188 lines • 10.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestOperations = 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 OperationUtils_1 = require("../OperationUtils");
const OperationsBase_1 = require("../../base/OperationsBase");
const EntityListIteratorImpl_1 = require("../../base/iterators/EntityListIteratorImpl");
const imodels_client_management_1 = require("@itwin/imodels-client-management");
const ClashDetectionClient_1 = require("../../ClashDetectionClient");
class TestOperations extends OperationsBase_1.OperationsBase {
constructor(options) {
super(options);
}
/**
* Gets Tests for a specific project. This method returns Tests in their summary representation. The returned
* iterator internally queries entities in pages. Wraps the
* {@link https://developer.bentley.com/apis/clash-detection/operations/get-clashdetection-tests/ Get Tests}
* operation from Clash Detection API.
* @param {ParamsToGetTestList} params parameters for this operation. See {@link ParamsToGetTestList}.
* @returns {EntityListIterator<TestItem>} iterator for Test list. See {@link EntityListIterator},
* {@link TestItem}.
*/
getList(params) {
const entityCollectionAccessor = (response) => {
const tests = response.tests;
return tests;
};
OperationUtils_1.OperationUtils.ensureAccessTokenProvided(params.accessToken, this._options.accessTokenCallback);
return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => {
var _a, _b;
return this.getEntityCollectionPage({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
accessToken: (_a = params.accessToken) !== null && _a !== void 0 ? _a : await this._options.accessTokenCallback(),
url: this._options.urlFormatter.getTestListUrl({ urlParams: params.urlParams }),
entityCollectionAccessor,
userMetadata: (_b = params.userMetadata) !== null && _b !== void 0 ? _b : false,
});
});
}
/**
* Gets a single Test identified by id. This method returns a Test in its full representation.
* Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/get-clashdetection-test/
* Get Test} operation from Clash Detection API.
* @param {ParamsToGetTest} params parameters for this operation. See {@link ParamsToGetTest}.
* @returns {Promise<TestDetails>} a Test with specified id. See {@link TestDetails}.
*/
async getSingle(params) {
const { accessToken, testId, userMetadata } = params;
OperationUtils_1.OperationUtils.ensureAccessTokenProvided(accessToken, this._options.accessTokenCallback);
const response = await this.sendGetRequest({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
accessToken: accessToken !== null && accessToken !== void 0 ? accessToken : await this._options.accessTokenCallback(),
url: this._options.urlFormatter.getSingleTestUrl({ testId }),
userMetadata: userMetadata !== null && userMetadata !== void 0 ? userMetadata : false,
});
return response.test;
}
/**
* Creates a Test. Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/create-clashdetection-test/
* Create Test} operation from Clash Detection API.
* @param {ParamsToCreateTest} params parameters for this operation. See {@link ParamsToCreateTest}.
* @returns {Promise<Test>} newly created Test. See {@link Test}.
*/
async create(params) {
var _a;
const body = {
projectId: params.projectId,
displayName: params.displayName,
description: params.description,
setA: params.setA,
setB: params.setB,
suppressTouching: params.suppressTouching,
touchingTolerance: params.touchingTolerance,
includeSubModels: params.includeSubModels,
suppressionRules: params.suppressionRules,
advancedSettings: params.advancedSettings,
};
OperationUtils_1.OperationUtils.ensureAccessTokenProvided(params.accessToken, this._options.accessTokenCallback);
const response = await this.sendPostRequest({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
accessToken: (_a = params.accessToken) !== null && _a !== void 0 ? _a : await this._options.accessTokenCallback(),
url: this._options.urlFormatter.createTestUrl(),
body,
});
return response.test;
}
/**
* Updates a Test. Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/update-clashdetection-test/
* Update Test} operation from Clash Detection API.
* @param {ParamsToUpdateTest} params parameters for this operation. See {@link ParamsToUpdateTest}.
* @returns {Promise<Test>} newly updated Test. See {@link Test}.
*/
async update(params) {
var _a;
const body = {
displayName: params.displayName,
description: params.description,
setA: params.setA,
setB: params.setB,
suppressTouching: params.suppressTouching,
touchingTolerance: params.touchingTolerance,
includeSubModels: params.includeSubModels,
suppressionRules: params.suppressionRules,
advancedSettings: params.advancedSettings,
};
OperationUtils_1.OperationUtils.ensureAccessTokenProvided(params.accessToken, this._options.accessTokenCallback);
const response = await this.sendPutRequest({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
accessToken: (_a = params.accessToken) !== null && _a !== void 0 ? _a : await this._options.accessTokenCallback(),
url: this._options.urlFormatter.updateTestUrl(params),
body,
});
return response.test;
}
/**
* Runs a test. Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/run-clashdetection-test/
* Run test} operation from Clash Detection API.
* @param {ParamsToRunTest} params parameters for this operation. See {@link ParamsToRunTest}.
* @returns {Promise<Run>} newly started Run. See {@link Run}.
*/
async runTest(params) {
var _a;
OperationUtils_1.OperationUtils.ensureAccessTokenProvided(params.accessToken, this._options.accessTokenCallback);
// If namedVersionId is not specified, then try to get latest version as default
if (params.namedVersionId === undefined) {
const iModelsClient = new imodels_client_management_1.IModelsClient();
let authorization;
if (params.accessToken) {
authorization = ClashDetectionClient_1.ClashDetectionClient.toAuthorizationCallback(params.accessToken);
}
else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const accessToken = await this._options.accessTokenCallback();
authorization = ClashDetectionClient_1.ClashDetectionClient.toAuthorizationCallback(accessToken);
}
const getNamedVersionListParams = {
authorization,
iModelId: params.iModelId,
urlParams: {
$orderBy: {
property: imodels_client_management_1.NamedVersionOrderByProperty.ChangesetIndex,
operator: imodels_client_management_1.OrderByOperator.Descending,
},
},
};
const namedVersionsIterator = iModelsClient.namedVersions.getMinimalList(getNamedVersionListParams);
const namedVersions = await (0, imodels_client_management_1.toArray)(namedVersionsIterator);
if (namedVersions.length === 0) {
return undefined;
}
params.namedVersionId = namedVersions[0].id;
}
const body = {
testId: params.testId,
iModelId: params.iModelId,
namedVersionId: params.namedVersionId,
testSettings: params.testSettings,
};
const response = await this.sendPostRequest({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
accessToken: (_a = params.accessToken) !== null && _a !== void 0 ? _a : await this._options.accessTokenCallback(),
url: this._options.urlFormatter.runTestUrl(),
body,
});
return response.run;
}
/**
* Deletes a single Test identified by id.
* Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/delete-clashdetection-test/
* Get Rule} operation from Clash Detection API.
* @param {ParamsToDeleteTest} params parameters for this operation. See {@link ParamsToDeleteTest}.
* @returns {Promise<void>}.
*/
async delete(params) {
const { accessToken, testId } = params;
OperationUtils_1.OperationUtils.ensureAccessTokenProvided(accessToken, this._options.accessTokenCallback);
await this.sendDeleteRequest({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
accessToken: accessToken !== null && accessToken !== void 0 ? accessToken : await this._options.accessTokenCallback(),
url: this._options.urlFormatter.deleteTestUrl({ testId }),
});
}
}
exports.TestOperations = TestOperations;
//# sourceMappingURL=TestOperations.js.map