1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.BaseExplorerService = void 0;
|
4 | const lodash_1 = require("lodash");
|
5 | class BaseExplorerService {
|
6 | getModules(modulesContainer, include) {
|
7 | if (!include || (0, lodash_1.isEmpty)(include)) {
|
8 | return [...modulesContainer.values()];
|
9 | }
|
10 | const explicitlyWhitelisted = this.includeWhitelisted(modulesContainer, include);
|
11 | const modulesToInclude = [];
|
12 | const toCheck = [...explicitlyWhitelisted];
|
13 | while (toCheck.length) {
|
14 | const moduleRef = toCheck.pop();
|
15 | if (!modulesToInclude.includes(moduleRef)) {
|
16 | modulesToInclude.push(moduleRef);
|
17 | toCheck.push(...moduleRef.imports);
|
18 | }
|
19 | }
|
20 | return modulesToInclude;
|
21 | }
|
22 | includeWhitelisted(modulesContainer, include) {
|
23 | const modules = [...modulesContainer.values()];
|
24 | return modules.filter(({ metatype }) => include.some((item) => item === metatype));
|
25 | }
|
26 | flatMap(modules, callback) {
|
27 | const invokeMap = () => {
|
28 | return modules.map((moduleRef) => {
|
29 | const providers = [...moduleRef.providers.values()];
|
30 | return providers.map((wrapper) => callback(wrapper, moduleRef));
|
31 | });
|
32 | };
|
33 | return (0, lodash_1.flattenDeep)(invokeMap()).filter(lodash_1.identity);
|
34 | }
|
35 | groupMetadata(resolvers) {
|
36 | const groupByType = (0, lodash_1.groupBy)(resolvers, (metadata) => metadata.type);
|
37 | const groupedMetadata = (0, lodash_1.mapValues)(groupByType, (resolversArr) => resolversArr.reduce((prev, curr) => ({
|
38 | ...prev,
|
39 | [curr.name]: curr.callback,
|
40 | }), {}));
|
41 | return groupedMetadata;
|
42 | }
|
43 | }
|
44 | exports.BaseExplorerService = BaseExplorerService;
|