1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.validateDomainAndModule = exports.getModuleBaseUri = exports.getModuleDomain = exports.moduleToUri = exports.domainToUri = void 0;
|
4 | const bf_types_1 = require("bf-types");
|
5 | const utils_1 = require("./utils");
|
6 | const domainUriMap = new Map();
|
7 | const moduleUriMap = new Map();
|
8 | for (const domain of Object.values(bf_types_1.DOMAINS)) {
|
9 | domainUriMap.set(domain, utils_1.toLowerCamel(domain));
|
10 | }
|
11 | for (const module of Object.values(bf_types_1.ALL_MODULES)) {
|
12 | moduleUriMap.set(module, utils_1.toLowerCamel(module));
|
13 | }
|
14 | const moduleToDomainMap = new Map();
|
15 | for (const domainName of Object.keys(bf_types_1.DOMAIN_MODULES)) {
|
16 | for (const moduleName of Object.keys(bf_types_1.DOMAIN_MODULES[domainName])) {
|
17 | moduleToDomainMap.set(moduleName, domainName);
|
18 | }
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function domainToUri(domainName) {
|
26 | const uri = domainUriMap.get(domainName);
|
27 | if (!uri) {
|
28 | throw new Error(`there is no URI for the ${domainName} domain`);
|
29 | }
|
30 | return uri;
|
31 | }
|
32 | exports.domainToUri = domainToUri;
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | function moduleToUri(moduleName) {
|
39 | const uri = moduleUriMap.get(moduleName);
|
40 | if (!uri) {
|
41 | throw new Error(`there is no URI for the ${moduleName} module`);
|
42 | }
|
43 | return uri;
|
44 | }
|
45 | exports.moduleToUri = moduleToUri;
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function getModuleDomain(moduleName) {
|
52 | return moduleToDomainMap.get(moduleName) || null;
|
53 | }
|
54 | exports.getModuleDomain = getModuleDomain;
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | function getModuleBaseUri(moduleName, uri) {
|
61 | const domainName = getModuleDomain(moduleName);
|
62 | return `${domainToUri(domainName)}/${moduleToUri(moduleName)}${uri ? `/${uri}` : ''}`;
|
63 | }
|
64 | exports.getModuleBaseUri = getModuleBaseUri;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | function validateDomainAndModule(domainName, moduleName) {
|
72 | if (!bf_types_1.DOMAINS[domainName]) {
|
73 | throw new Error(`${domainName} is not a valid entity domain`);
|
74 | }
|
75 | if (!bf_types_1.ALL_MODULES[moduleName]) {
|
76 | throw new Error(`${moduleName} is not a valid entity module`);
|
77 | }
|
78 | const domainModules = bf_types_1.DOMAIN_MODULES[domainName];
|
79 | if (typeof domainModules[moduleName] !== 'string') {
|
80 | throw new Error(`${module} is not a module of the ${utils_1.toDisplay(domainName)}`);
|
81 | }
|
82 | }
|
83 | exports.validateDomainAndModule = validateDomainAndModule;
|