@itwin/property-validation-client
Version:
Property Validation client for the iTwin platform
94 lines • 3.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertyValidationApiUrlFormatter = void 0;
class PropertyValidationApiUrlFormatter {
constructor(baseUrl) {
this.baseUrl = baseUrl;
}
getSingleRuleUrl(params) {
return `${this.baseUrl}/rules/${params.ruleId}`;
}
getRuleListUrl(params) {
return `${this.baseUrl}/rules${this.formQueryString({ ...params.urlParams })}`;
}
createRuleUrl() {
return `${this.baseUrl}/rules`;
}
updateRuleUrl(params) {
return `${this.baseUrl}/rules/${params.ruleId}`;
}
deleteRuleUrl(params) {
return `${this.baseUrl}/rules/${params.ruleId}`;
}
getTemplateListUrl(params) {
return `${this.baseUrl}/ruleTemplates${this.formQueryString({ ...params.urlParams })}`;
}
getSingleTestUrl(params) {
return `${this.baseUrl}/tests/${params.testId}`;
}
getTestListUrl(params) {
return `${this.baseUrl}/tests${this.formQueryString({ ...params.urlParams })}`;
}
createTestUrl() {
return `${this.baseUrl}/tests`;
}
updateTestUrl(params) {
return `${this.baseUrl}/tests/${params.testId}`;
}
deleteTestUrl(params) {
return `${this.baseUrl}/tests/${params.testId}`;
}
getSingleRunUrl(params) {
return `${this.baseUrl}/runs/${params.runId}`;
}
getRunListUrl(params) {
return `${this.baseUrl}/runs${this.formQueryString({ ...params.urlParams })}`;
}
runTestUrl() {
return `${this.baseUrl}/runs`;
}
deleteRunUrl(params) {
return `${this.baseUrl}/runs/${params.runId}`;
}
getResultUrl(params) {
return `${this.baseUrl}/results/${params.resultId}`;
}
getPropertiesInfoUrl(params) {
return `${this.baseUrl}/properties/imodels/${params.iModelId}${this.formQueryString({ ...params.urlParams })}`;
}
extractSchemaInfoUrl(params) {
return `${this.baseUrl}/schema/imodels/${params.iModelId}}`;
}
formQueryString(urlParameters) {
let queryString = "";
for (const urlParameterKey in urlParameters) {
if (!Object.prototype.hasOwnProperty.call(urlParameters, urlParameterKey)) {
continue;
}
const urlParameterValue = urlParameters[urlParameterKey];
if (!this.shouldAppendToUrl(urlParameterValue)) {
continue;
}
queryString = this.appendToQueryString(queryString, urlParameterKey, urlParameterValue);
}
return queryString;
}
shouldAppendToUrl(urlParameterValue) {
if (urlParameterValue === null || urlParameterValue === undefined) {
return false;
}
if (typeof urlParameterValue === "string" && !urlParameterValue.trim()) {
return false;
}
return true;
}
appendToQueryString(existingQueryString, parameterKey, parameterValue) {
const separator = existingQueryString.length === 0 ? "?" : "&";
return `${existingQueryString}${separator}${parameterKey}=${this.stringify(parameterValue)}`;
}
stringify(urlParameterValue) {
return urlParameterValue.toString();
}
}
exports.PropertyValidationApiUrlFormatter = PropertyValidationApiUrlFormatter;
//# sourceMappingURL=PropertyValidationApiUrlFormatter.js.map