-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
77 lines (66 loc) · 2.61 KB
/
Copy pathindex.ts
File metadata and controls
77 lines (66 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { DependencyInjectionContainer } from '@shared/dependencyInjection/DependencyInjectionContainer';
import { ContainerRegisteredModuleDescriptor } from '@shared/dependencyInjection/DependencyInjectionTypes';
import { getDependencyTree } from '@shared/visualServer/dependencyTree';
import { generateHtml } from '@shared/visualServer/generateHtml';
export type Method = {
name: string;
definition: string;
returnStructure: TypeNode | string;
};
export type TypeNode =
| { kind: 'primitive'; type: string }
| { kind: 'reference'; type: string; refId: string }
| { kind: 'array'; elementType: TypeNode }
| { kind: 'union'; types: TypeNode[] }
| { kind: 'object'; type: string; properties: PropertyNode[] }
| { kind: 'enum'; type: string; members: string[] }
| { kind: 'promise'; type: TypeNode };
export type PropertyNode = {
name: string;
type: TypeNode;
optional: boolean;
};
export type EntryPointMetaData = {
name: string;
version: string;
containerName: string;
methods?: Method[];
};
type ContainerName = string;
const entryPoints = new Map<EntryPointMetaData, unknown>();
const containers = new Map<ContainerName, unknown>();
const dependencyGraph: any[] = [];
function registerContainer(name: string = '', container: unknown): void {
containers.set(name, container);
}
function registerEntryPoint(entryPointClass: unknown, entryPointMetaData: EntryPointMetaData): void {
entryPoints.set(entryPointMetaData, entryPointClass);
}
function generateGraphDependency(): void {
const containersList = Array.from(containers);
containersList.forEach((containerEntry: [string, any]) => {
const container: DependencyInjectionContainer = containerEntry[1];
const containerName = containerEntry[0];
const serviceTrees: any[] = []; // Local tree for this service
const entryPointList = Array.from(entryPoints);
entryPointList
.filter((entryPoint) => {
return entryPoint[0].containerName === containerName;
})
.forEach((entryPoint) => {
const entrypointMetaData = entryPoint[0];
container.register({ serviceVersion: DependencyInjectionContainer.asValue(entrypointMetaData.version) });
const containerRegisteredModuleDescriptors: ContainerRegisteredModuleDescriptor[] = container.listModules();
const tree = getDependencyTree(container, entrypointMetaData, containerRegisteredModuleDescriptors);
dependencyGraph.push(tree);
serviceTrees.push(tree);
});
generateHtml(serviceTrees, containerName);
});
}
export const visualServer = {
registerContainer,
registerEntryPoint,
dependencyGraph,
generateGraphDependency,
};