Property Validation client for the iTwin platform
npm install @itwin/property-validation-clientIn alignment with our ongoing portfolio simplification efforts, Bentley has made the strategic decision to discontinue support for iTwin Design Validation, effective August 30, 2024.
Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.
iTwin.js is an open source platform for creating, querying, modifying, and displaying Infrastructure Digital Twins. To learn more about the iTwin Platform and its APIs, visit the iTwin developer portal.
If you have questions, or wish to contribute to iTwin.js, see our Contributing guide.
The __@itwin/property-validation-client__ package consists of thin wrapper functions for sending requests to the iTwin Validation API. There are CRUD functions for the four components of validation: rules, tests, runs and results. Define validation criteria in rules, add rules to tests, run the tests for versions of iModels, and retrieve the validation results. Visit the Property Validation API for more details.
client.imodel.extractSchemaInfo(params: ParamsToExtractSchemaInfo): Promiseclient.schema.getPropertiesInfo(params: ParamsToGetPropertiesInfo): Promiseclient.templates.getList(params: ParamsToGetTemplateList): EntityListIteratorclient.rules.create(params: ParamsToCreateRule): Promiseclient.rules.update(params: ParamsToUpdateRule): Promiseclient.rules.getMinimalList(params: ParamsToGetRuleList): EntityListIteratorclient.rules.getRepresentationList(params: ParamsToGetRuleList): EntityListIteratorclient.rules.getSingle(params: ParamsToGetRule): Promiseclient.tests.create(params: ParamsToCreateTest): Promiseclient.tests.update(params: ParamsToUpdateTest): Promiseclient.tests.getSingle(params: ParamsToGetTest): Promiseclient.tests.getList(params: ParamsToGetTestList): EntityListIteratorclient.tests.runTest(params: ParamsToRunTest): Promiseclient.runs.getMinimalList(params: ParamsToGetRunList): Promise](#get-all-property-validation-runs--minimal)client.runs.getRepresentationList(params: ParamsToGetRunList): Promise](#get-all-property-validation-runs---detailed)client.runs.getSingle(params: ParamsToGetRun): Promiseclient.results.get(params: ParamsToGetResult): Promiseclient.rules.delete(params: ParamsToDeleteRule): Promiseclient.tests.delete(params: ParamsToDeleteTest): Promiseclient.runs.delete(params: ParamsToDeleteRun): PromiseThere are two ways to provide the authorization token for the wrapper functions:
1. Set accessToken in parameters object every time a wrapper function is called (as shown in usage examples below).
2. Provide a callback function to the PropertyValidationClient constructor. This callback will be called by the wrapper function if the accessToken parameter in Option 1 is not provided.
``typescript
import { PropertyValidationClient, PropertyValidationClientOptions } from "@itwin/property-validation-client";
public static initWrapperClient(accessToken: string, projectId: string): PropertyValidationClient {
const options: PropertyValidationClientOptions = {};
const accessTokenCallback = async () => this.getAccessToken();
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient(options, accessTokenCallback);
}
public static async getAccessToken(): Promise
return "Bearer ey..."
}
`
typescript
import { EntityListIterator, ParamsToGetTemplateList, PropertyValidationClient, RuleTemplate } from "@itwin/property-validation-client";/* Function that queries all rule templates for a particular project and prints their ids to the console. /
async function printRuleTemplateIds(accessToken: string, projectId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetTemplateList = {
accessToken,
urlParams: {
projectId
}
};
const templatesIterator: EntityListIterator = propertyValidationClient.templates.getList(params);
for await (const template of templatesIterator)
console.log(template.id);
}
`$3
`typescript
import { ParamsToCreateRule, PropertyValidationClient, Rule } from "@itwin/property-validation-client";/* Function that creates a new property validation rule and prints its id to the console. /
async function createPropertyValidationRule(accessToken: string, templateId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToCreateRule = {
accessToken,
templateId,
displayName: "TestRule1",
description: "Test rule 1",
severity: "medium",
ecSchema: "ArchitecturalPhysical",
ecClass: "Door",
whereClause: "Roll = '10'",
dataType: "property",
functionParameters: {
propertyName: "Pitch",
upperBound: "2"
}
};
const rule: Rule = await propertyValidationClient.rules.create(params);
console.log(rule.id);
}
`$3
`typescript
import { ParamsToUpdateRule, PropertyValidationClient, Rule } from "@itwin/property-validation-client";/* Function that updates a new property validation rule and prints its id to the console. /
async function updatePropertyValidationRule(accessToken: string, ruleId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToUpdateRule = {
accessToken,
ruleId,
displayName: "TestRule1 - updated",
description: "Test rule 1",
severity: "high",
ecSchema: "ArchitecturalPhysical",
ecClass: "Door",
whereClause: "Roll = '10'"
};
const rule: Rule = await propertyValidationClient.rules.update(params);
console.log(rule.id);
}
`$3
`typescript
import { EntityListIterator, MinimalRule, ParamsToGetRuleList, PropertyValidationClient } from "@itwin/property-validation-client";/* Function that queries all rules for a particular project and prints their ids to the console. /
async function printRuleIds(accessToken: string, projectId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetRuleList = {
accessToken,
urlParams: {
projectId
}
};
const rulesIterator: EntityListIterator = propertyValidationClient.rules.getMinimalList(params);
for await (const rule of rulesIterator)
console.log(rule.id);
}
`$3
`typescript
import { EntityListIterator, ParamsToGetRuleList, PropertyValidationClient, RuleDetails } from "@itwin/property-validation-client";/* Function that queries all rules for a particular project and prints their ids to the console. /
async function printRuleIds(accessToken: string, projectId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetRuleList = {
accessToken,
urlParams: {
projectId
},
userMetadata: true,
};
const rulesIterator: EntityListIterator = propertyValidationClient.rules.getRepresentationList(params);
for await (const rule of rulesIterator)
console.log(rule.id);
}
`$3
`typescript
import { ParamsToGetRule, PropertyValidationClient, RuleDetails } from "@itwin/property-validation-client";/* Function that gets a property validation rule and prints its name. /
async function getPropertyValidationRule(accessToken: string, ruleId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetRule = {
accessToken,
ruleId,
userMetadata: true,
};
const rule: RuleDetails = await propertyValidationClient.rules.getSingle(params);
console.log(rule.displayName);
}
`$3
`typescript
import { ParamsToDeleteRule, PropertyValidationClient } from "@itwin/property-validation-client";/* Function that deletes a property validation rule. /
async function deletePropertyValidationRule(accessToken: string, ruleId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToDeleteRule = {
accessToken,
ruleId
};
await propertyValidationClient.rules.delete(params);
}
`$3
`typescript
import { ParamsToCreateTest, PropertyValidationClient, Test } from "@itwin/property-validation-client";/* Function that creates a new property validation test and prints its id to the console. /
async function createPropertyValidationTest(accessToken: string, projectId: string, rules: string[]): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToCreateTest = {
accessToken,
projectId,
displayName: "Test1",
description: "Test 1",
stopExecutionOnFailure: false,
rules,
};
const test: Test = await propertyValidationClient.tests.create(params);
console.log(test.id);
}
`$3
`typescript
import { ParamsToUpdateTest, PropertyValidationClient, Test } from "@itwin/property-validation-client";/* Function that updates a new property validation test and prints its id to the console. /
async function updatePropertyValidationTest(accessToken: string, testId: string, rules: string[]): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToUpdateTest = {
accessToken,
testId,
displayName: "Test1 - updated",
description: "Test 1",
stopExecutionOnFailure: false,
rules,
};
const test: Test = await propertyValidationClient.tests.update(params);
console.log(test.id);
}
`$3
`typescript
import { EntityListIterator, ParamsToGetTestList, PropertyValidationClient, TestItem } from "@itwin/property-validation-client";
/* Function that queries all tests for a particular project and prints their ids to the console. /
async function printTestIds(accessToken: string, projectId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetTestList = {
accessToken,
urlParams: {
projectId
},
userMetadata: true,
};
const testsIterator: EntityListIterator = propertyValidationClient.tests.getList(params);
for await (const test of testsIterator)
console.log(test.id);
}
`$3
`typescript
import { ParamsToGetTest, PropertyValidationClient, TestDetails } from "@itwin/property-validation-client";/* Function that gets a property validation test and prints its name. /
async function getPropertyValidationTest(accessToken: string, testId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetTest = {
accessToken,
testId,
userMetadata: true,
};
const test: TestDetails = await propertyValidationClient.tests.getSingle(params);
console.log(test.displayName);
}
`$3
`typescript
import { ParamsToRunTest, PropertyValidationClient, Run, TestSettings } from "@itwin/property-validation-client";/* Function that runs a property validation test and prints its run id. /
async function runPropertyValidationTest(accessToken: string, testId: string, iModelId: string, namedVersionId?: string, testSettings?: TestSettings): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToRunTest = {
accessToken,
testId,
iModelId,
namedVersionId, // Optional - defaults to latest version
testSettings, // Optional
};
const run: Run = await propertyValidationClient.tests.runTest(params);
console.log(run.id);
}
`$3
`typescript
import { ParamsToDeleteTest, PropertyValidationClient } from "@itwin/property-validation-client";/* Function that deletes a property validation test. /
async function deletePropertyValidationTest(accessToken: string, testId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToDeleteTest = {
accessToken,
testId
};
await propertyValidationClient.tests.delete(params);
}
`$3
`typescript
import { MinimalRun, ParamsToGetRunList, PropertyValidationClient } from "@itwin/property-validation-client";
/* Function that queries all runs for a particular project and prints their ids to the console. /
async function printRunIds(accessToken: string, projectId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetRunList = {
accessToken,
urlParams: {
projectId
}
};
const runs: MinimalRun[] = await propertyValidationClient.runs.getMinimalList(params);
runs.forEach((run) => {
console.log(run.id);
});
}
`$3
`typescript
import { ParamsToGetRunList, PropertyValidationClient, RunDetails } from "@itwin/property-validation-client";
/* Function that queries all runs for a particular project and prints their ids to the console. /
async function printRunIds(accessToken: string, projectId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetRunList = {
accessToken,
urlParams: {
projectId
}
};
const runs: RunDetails[] = await propertyValidationClient.runs.getRepresentationList(params);
runs.forEach((run) => {
console.log(run.id);
});
}
`$3
`typescript
import { ParamsToGetRun, PropertyValidationClient, RunDetails } from "@itwin/property-validation-client";/* Function that gets a property validation run and prints its name and status. /
async function getPropertyValidationRun(accessToken: string, runId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetRun = {
accessToken,
runId
};
const run: RunDetails = await propertyValidationClient.runs.getSingle(params);
console.log('${run.displayName}: ${run.status}');
}
`$3
`typescript
import { ParamsToDeleteRun, PropertyValidationClient } from "@itwin/property-validation-client";/* Function that deletes a property validation run. /
async function deletePropertyValidationRun(accessToken: string, runId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToDeleteRun = {
accessToken,
runId
};
await propertyValidationClient.runs.delete(params);
}
`$3
`typescript
import { ParamsToGetResult, PropertyValidationClient, ResponseFromGetResult } from "@itwin/property-validation-client";/* Function that gets a property validation result and prints the count of validation failures. /
async function getPropertyValidationResult(accessToken: string, resultId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetResult = {
accessToken,
resultId
};
const response: ResponseFromGetResult = await propertyValidationClient.results.get(params);
console.log('Results count: ${response.result.length.toString()}');
}
`$3
`typescript
import { PropertyValidationClient, ParamsToExtractSchemaInfo } from "@itwin/property-validation-client";
/* Function that extracts schema info. /
async function extractSchemaInfo(accessToken: string, projectId: string, iModelId: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToExtractSchemaInfo = {
accessToken,
iModelId,
urlParams: {
projectId
}
};
await propertyValidationClient.schema.extractSchemaInfo(params);
}
`$3
`typescript
import { PropertyValidationClient, ParamsToGetPropertiesInfo, PropertiesInfo } from "@itwin/property-validation-client";
/* Function that gets the iModel properties information and prints the extraction status. /
async function getPropertiesInfo(accessToken: string, projectId: string, iModelId: string, filter: string): Promise {
const propertyValidationClient: PropertyValidationClient = new PropertyValidationClient();
const params: ParamsToGetPropertiesInfo = {
iModelId,
urlParams: {
projectId,
filter,
},
};
const propertiesInfo: PropertiesInfo = await propertyValidationClient.schema.getPropertiesInfo(params);
console.log('Status: ${propertiesInfo.status}');
}
``