UNPKG

cspace-ui

Version:
50 lines (47 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serviceUriToLocation = exports.default = void 0; var _configHelpers = require("./configHelpers"); const uriPattern = /^\/(.*?)\/(.*?)(\/items\/(.*?))?$/; const serviceUriToLocation = (config, uri) => { if (!uri) { return undefined; } const match = uriPattern.exec(uri); if (!match) { return undefined; } const servicePath = match[1]; let csid; let vocabularyServicePath; /* eslint-disable prefer-destructuring */ if (match[3]) { csid = match[4]; vocabularyServicePath = match[2]; } else { csid = match[2]; } /* eslint-enable prefer-destructuring */ const recordTypeConfig = (0, _configHelpers.getRecordTypeConfigByServicePath)(config, servicePath); if (!recordTypeConfig) { return undefined; } const recordType = recordTypeConfig.name; const parts = ['/record', recordType]; if (vocabularyServicePath) { const vocabularyConfig = (0, _configHelpers.getVocabularyConfigByServicePath)(recordTypeConfig, vocabularyServicePath); const vocabulary = vocabularyConfig ? vocabularyConfig.name : undefined; if (!vocabulary) { return undefined; } parts.push(vocabulary); } parts.push(csid); return { pathname: parts.join('/') }; }; exports.serviceUriToLocation = serviceUriToLocation; var _default = exports.default = {};