UNPKG

@itwin/clash-detection-client

Version:

Clash Detection client for the iTwin platform

96 lines 3.54 kB
export class ClashDetectionApiUrlFormatter { constructor(baseUrl) { this.baseUrl = baseUrl; } getSingleRuleUrl(params) { return `${this.baseUrl}/suppressionRules/${params.ruleId}`; } getRuleListUrl(params) { return `${this.baseUrl}/suppressionRules${this.formQueryString({ ...params.urlParams })}`; } createRuleUrl() { return `${this.baseUrl}/suppressionRules`; } updateRuleUrl(params) { return `${this.baseUrl}/suppressionRules/${params.ruleId}`; } deleteRuleUrl(params) { return `${this.baseUrl}/suppressionRules/${params.ruleId}`; } getTemplateListUrl(params) { return `${this.baseUrl}/suppressionRuleTemplates${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}`; } getSchemaInfoUrl(params) { return `${this.baseUrl}/schemas/imodels/${params.iModelId}${this.formQueryString({ ...params.urlParams })}`; } extractSchemaInfoUrl(params) { return `${this.baseUrl}/schemas/imodels/${params.iModelId}`; } getModelsAndCategoriesUrl(params) { return `${this.baseUrl}/modelsAndCategories/imodels/${params.iModelId}${this.formQueryString({ ...params.urlParams })}`; } extractModelsAndCategoriesUrl(params) { return `${this.baseUrl}/modelsAndCategories/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(); } } //# sourceMappingURL=ClashDetectionApiUrlFormatter.js.map