UNPKG

@itwin/property-validation-client

Version:
159 lines 8.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RuleOperations = 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 RuleOperations extends OperationsBase_1.OperationsBase { constructor(options) { super(options); } /** * Gets Rules for a specific project. This method returns Rules in their minimal representation. The * returned iterator internally queries entities in pages. Wraps the * {@link https://developer.bentley.com/apis/validation/operations/get-validation-propertyvalue-rules/ Get Rules} * operation from Property Validation API. * @param {ParamsToGetRuleList} params parameters for this operation. See {@link ParamsToGetRuleList}. * @returns {EntityListIterator<MinimalRule>} iterator for Rule list. See {@link EntityListIterator}, * {@link MinimalRule}. */ getMinimalList(params) { const entityCollectionAccessor = (response) => { const rules = response.rules; 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 Rules for a specific project. This method returns Rules in their full representation. The returned * iterator internally queries entities in pages. Wraps the * {@link https://developer.bentley.com/apis/validation/operations/get-validation-propertyvalue-rules/ Get Rules} * operation from Property Validation API. * @param {ParamsToGetRuleList} params parameters for this operation. See {@link ParamsToGetRuleList}. * @returns {EntityListIterator<RuleDetails>} iterator for Rule list. See {@link EntityListIterator}, * {@link RuleDetails}. */ getRepresentationList(params) { const entityCollectionAccessor = (response) => { const rules = response.rules; 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 Rule identified by id. This method returns a Rule in its full representation. * Wraps the {@link https://developer.bentley.com/apis/validation/operations/get-validation-propertyvalue-rule/ * Get Rule} operation from Property Validation API. * @param {ParamsToGetRule} params parameters for this operation. See {@link ParamsToGetRule}. * @returns {Promise<RuleDetails>} a Rule with specified id. See {@link RuleDetails}. */ 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.rule; } /** * Deletes a single Rule identified by id. * Wraps the {@link https://developer.bentley.com/apis/validation/operations/delete-validation-propertyvalue-rule/ * Delete Rule} operation from Property Validation API. * @param {ParamsToDeleteRule} params parameters for this operation. See {@link ParamsToDeleteRule}. * @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 Rule. Wraps the {@link https://developer.bentley.com/apis/validation/operations/create-validation-propertyvalue-rule/ * Create Rule} operation from Property Validation API. * @param {ParamsToCreateRule} params parameters for this operation. See {@link ParamsToCreateRule}. * @returns {Promise<Rule>} newly created Rule. See {@link Rule}. */ async create(params) { var _a; const body = { templateId: params.templateId, displayName: params.displayName, description: params.description, ecClass: params.ecClass, ecSchema: params.ecSchema, whereClause: params.whereClause, severity: params.severity, dataType: params.dataType, functionParameters: params.functionParameters, }; 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.rule; } /** * Updates a Rule. Wraps the {@link https://developer.bentley.com/apis/validation/operations/update-validation-propertyvalue-rule/ * Update Rule} operation from Property Validation API. * @param {ParamsToUpdateRule} params parameters for this operation. See {@link ParamsToUpdateRule}. * @returns {Promise<Rule>} newly updated Rule. See {@link Rule}. */ async update(params) { var _a; const body = { displayName: params.displayName, description: params.description, ecClass: params.ecClass, ecSchema: params.ecSchema, whereClause: params.whereClause, severity: params.severity, }; 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.rule; } } exports.RuleOperations = RuleOperations; //# sourceMappingURL=RuleOperations.js.map