UNPKG

@itwin/property-validation-client

Version:
178 lines 9.69 kB
"use strict"; 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 PropertyValidationClient_1 = require("../../PropertyValidationClient"); 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/validation/operations/get-validation-propertyvalue-tests/ Get Tests} * operation from Property Validation 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/validation/operations/get-validation-propertyvalue-test/ * Get Test} operation from Property Validation 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/validation/operations/create-validation-propertyvalue-test/ * Create Test} operation from Property Validation 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, stopExecutionOnFailure: params.stopExecutionOnFailure, rules: params.rules, }; 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/validation/operations/update-validation-propertyvalue-test/ * Update Test} operation from Property Validation 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, stopExecutionOnFailure: params.stopExecutionOnFailure, rules: params.rules, }; 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/validation/operations/run-validation-propertyvalue-test/ * Run test} operation from Property Validation 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 = PropertyValidationClient_1.PropertyValidationClient.toAuthorizationCallback(params.accessToken); } else { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const accessToken = await this._options.accessTokenCallback(); authorization = PropertyValidationClient_1.PropertyValidationClient.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/validation/operations/delete-validation-propertyvalue-test/ * Get Rule} operation from Property Validation 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