forked from xndlnk/microservice-visualization
-
Notifications
You must be signed in to change notification settings - Fork 12
/
ms.ts
115 lines (90 loc) · 3.28 KB
/
ms.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { TypedNode, TypedEdge } from './core-typed'
import { Node, Metadata } from './core'
/**
* this model provides type-safe access to nodes in a microservice system.
*/
// TODO: move to msa/model/msa.ts
export class System extends TypedNode<NamePayload> {
constructor(id: string, metadata?: Metadata) {
super(id, { name: id }, metadata, System.name)
}
// TODO: these public methods could be generated from a model definition in the future
public addMicroService(name: string, extraPayload: any = {}, metadata?: Metadata): MicroService {
return this.addOrExtendNamedNode<MicroService>(MicroService, name, extraPayload, metadata)
}
public getMicroServices(): MicroService[] {
return this.getNodes<MicroService>(MicroService)
}
public findMicroService(name: string): MicroService {
return this.findTypedNodeWithName<MicroService>(MicroService, name)
}
public addMessageExchange(name: string, extraPayload: any = {}, metadata?: Metadata): MessageExchange {
return this.addOrExtendNamedNode<MessageExchange>(MessageExchange, name, extraPayload, metadata)
}
public getMessageExchanges(): MessageExchange[] {
return this.getNodes<MessageExchange>(MessageExchange)
}
public findMessageExchange(name: string): MessageExchange {
return this.findTypedNodeWithName<MessageExchange>(MessageExchange, name)
}
public addMessageQueue(name: string, extraPayload: any = {}, metadata?: Metadata): MicroService {
return this.addOrExtendNamedNode<MessageQueue>(MessageQueue, name, extraPayload, metadata)
}
public getSyncDataFlows(): SyncDataFlow[] {
return this.getEdges<SyncDataFlow>(SyncDataFlow)
}
public getAsyncEventFlows(): AsyncEventFlow[] {
return this.getEdges<AsyncEventFlow>(AsyncEventFlow)
}
}
export class MicroService extends TypedNode<MicroServicePayload> {
constructor(id: string, payload: MicroServicePayload, metadata?: Metadata) {
super(id, payload, metadata, MicroService.name)
}
}
export class MicroServicePayload {
name: string
env?: EnvEntry[]
labels?: any
sourceLocation?: string
}
type EnvEntry = {
name: string,
value: string
}
export class MessageExchangePayload {
name: string
}
export class MessageExchange extends TypedNode<MessageExchangePayload> {
constructor(id: string, payload: NamePayload, metadata?: Metadata) {
super(id, payload, metadata, MessageExchange.name)
}
}
export class MessageQueue extends TypedNode<NamePayload> {
constructor(id: string, payload: NamePayload, metadata?: Metadata) {
super(id, payload, metadata, MessageQueue.name)
}
}
export class NamePayload {
name: string
}
type AsyncEventFlowPayload = {
routingKey: string
}
// TODO: can this be simplified? too much boilerplate code for constructor
export class AsyncEventFlow extends TypedEdge<AsyncEventFlowPayload> {
constructor(source: Node, target: Node, payload?: AsyncEventFlowPayload, metadata?: Metadata) {
super(source, target, payload, metadata, AsyncEventFlow.name)
}
}
type SyncDataFlowPayload = {
definedEndpoints: Endpoint[]
}
type Endpoint = {
path: string
}
export class SyncDataFlow extends TypedEdge<SyncDataFlowPayload> {
constructor(source: Node, target: Node, payload?: SyncDataFlowPayload, metadata?: Metadata) {
super(source, target, payload, metadata, SyncDataFlow.name)
}
}