@itwin/clash-detection-client
Version:
Clash Detection client for the iTwin platform
150 lines • 8.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SuppressionRuleOperations = 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 CommonInterfaces_1 = require("../../base/interfaces/CommonInterfaces");
const EntityListIteratorImpl_1 = require("../../base/iterators/EntityListIteratorImpl");
class SuppressionRuleOperations extends OperationsBase_1.OperationsBase {
constructor(options) {
super(options);
}
/**
* Gets Suppression Rules for a specific project. This method returns Suppression Rules in their minimal representation. The
* returned iterator internally queries entities in pages. Wraps the
* {@link https://developer.bentley.com/apis/clash-detection/operations/get-clashdetection-rules/ Get Suppression Rules}
* operation from Clash Detection API.
* @param {ParamsToGetSuppressionRuleList} params parameters for this operation. See {@link ParamsToGetSuppressionRuleList}.
* @returns {EntityListIterator<MinimalSuppressionRule>} iterator for Suppression Rule list. See {@link EntityListIterator},
* {@link MinimalSuppressionRule}.
*/
getMinimalList(params) {
const entityCollectionAccessor = (response) => {
const rules = response.suppressionRules;
return rules;
};
OperationUtils_1.OperationUtils.ensureAccessTokenProvided(params.accessToken, this._options.accessTokenCallback);
return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => {
var _a;
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.getRuleListUrl({ urlParams: params.urlParams }),
preferReturn: CommonInterfaces_1.PreferReturn.Minimal,
entityCollectionAccessor,
userMetadata: false,
});
});
}
/**
* Gets Suppression Rules for a specific project. This method returns Suppression Rules in their full representation. The returned
* iterator internally queries entities in pages. Wraps the
* {@link https://developer.bentley.com/apis/clash-detection/operations/get-clashdetection-rules/ Get Suppression Rules}
* operation from Clash Detection API.
* @param {ParamsToGetSuppressionRuleList} params parameters for this operation. See {@link ParamsToGetSuppressionRuleList}.
* @returns {EntityListIterator<SuppressionRuleDetails>} iterator for Suppression Rule list. See {@link EntityListIterator},
* {@link SuppressionRuleDetails}.
*/
getRepresentationList(params) {
const entityCollectionAccessor = (response) => {
const rules = response.suppressionRules;
return rules;
};
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.getRuleListUrl({ urlParams: params.urlParams }),
preferReturn: CommonInterfaces_1.PreferReturn.Representation,
entityCollectionAccessor,
userMetadata: (_b = params.userMetadata) !== null && _b !== void 0 ? _b : false,
});
});
}
/**
* Gets a single Suppression Rule identified by id. This method returns a Suppression Rule in its full representation.
* Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/get-clashdetection-rule/
* Get Suppression Rule} operation from Clash Detection API.
* @param {ParamsToGetSuppressionRule} params parameters for this operation. See {@link ParamsToGetSuppressionRule}.
* @returns {Promise<SuppressionRuleDetails>} a Suppression Rule with specified id. See {@link SuppressionRuleDetails}.
*/
async getSingle(params) {
const { accessToken, ruleId, 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.getSingleRuleUrl({ ruleId }),
userMetadata: userMetadata !== null && userMetadata !== void 0 ? userMetadata : false,
});
return response.suppressionRule;
}
/**
* Deletes a single Suppression Rule identified by id.
* Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/delete-clashdetection-rule/
* Delete Suppression Rule} operation from Clash Detection API.
* @param {ParamsToDeleteSuppressionRule} params parameters for this operation. See {@link ParamsToDeleteSuppressionRule}.
* @returns {Promise<void>}.
*/
async delete(params) {
const { accessToken, ruleId } = 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.deleteRuleUrl({ ruleId }),
});
}
/**
* Creates a Suppression Rule. Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/create-clashdetection-rule/
* Create Suppression Rule} operation from Clash Detection API.
* @param {ParamsToCreateSuppressionRule} params parameters for this operation. See {@link ParamsToCreateSuppressionRule}.
* @returns {Promise<SuppressionRule>} newly created Suppression Rule. See {@link SuppressionRule}.
*/
async create(params) {
var _a;
const body = {
templateId: params.templateId,
displayName: params.displayName,
description: params.reason,
parameters: params.parameters,
};
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.createRuleUrl(),
body,
});
return response.suppressionRule;
}
/**
* Updates a Suppression Rule. Wraps the {@link https://developer.bentley.com/apis/clash-detection/operations/update-clashdetection-rule/
* Update Suppression Rule} operation from Clash Detection API.
* @param {ParamsToUpdateSuppressionRule} params parameters for this operation. See {@link ParamsToUpdateSuppressionRule}.
* @returns {Promise<SuppressionRule>} newly updated Suppression Rule. See {@link SuppressionRule}.
*/
async update(params) {
var _a;
const body = {
displayName: params.displayName,
description: params.reason,
};
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.updateRuleUrl(params),
body,
});
return response.suppressionRule;
}
}
exports.SuppressionRuleOperations = SuppressionRuleOperations;
//# sourceMappingURL=SuppressionRuleOperations.js.map