-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathIOClients.ts
More file actions
117 lines (90 loc) · 2.88 KB
/
Copy pathIOClients.ts
File metadata and controls
117 lines (90 loc) · 2.88 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
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
116
117
import { InstanceOptions } from '../HttpClient'
import { IOContext } from '../service/worker/runtime/typings'
import { Billing, Builder, MessagesGraphQL, Settings } from './apps'
import { CatalogGraphQL } from './apps/catalogGraphQL/index'
import { ID, MasterData, PaymentProvider } from './external'
import { Apps, Assets, BillingMetrics, Events, Registry, Router, VBase, Workspaces } from './infra'
import { IOClient, IOClientConstructor } from './IOClient'
import { Catalog, LicenseManager, Segment, Session, TenantClient } from './janus'
export type ClientsImplementation<T extends IOClients> = new (
clientOptions: Record<string, InstanceOptions>,
ctx: IOContext
) => T
export class IOClients {
private clients: Record<string, IOClient> = {}
constructor(private clientOptions: Record<string, InstanceOptions>, private ctx: IOContext) {}
public get apps() {
return this.getOrSet('apps', Apps)
}
public get assets() {
return this.getOrSet('assets', Assets)
}
public get billing() {
return this.getOrSet('billing', Billing)
}
public get billingMetrics() {
return this.getOrSet('billingMetrics', BillingMetrics)
}
public get builder() {
return this.getOrSet('builder', Builder)
}
public get events() {
return this.getOrSet('events', Events)
}
public get id() {
return this.getOrSet('id', ID)
}
public get licenseManager() {
return this.getOrSet('licenseManager', LicenseManager)
}
public get masterdata() {
return this.getOrSet('masterdata', MasterData)
}
public get messagesGraphQL() {
return this.getOrSet('messagesGraphQL', MessagesGraphQL)
}
public get registry() {
return this.getOrSet('registry', Registry)
}
public get router() {
return this.getOrSet('router', Router)
}
public get segment() {
return this.getOrSet('segment', Segment)
}
public get settings() {
return this.getOrSet('settings', Settings)
}
public get session() {
return this.getOrSet('session', Session)
}
public get tenant() {
return this.getOrSet('tenant', TenantClient)
}
public get vbase() {
return this.getOrSet('vbase', VBase)
}
public get workspaces() {
return this.getOrSet('workspaces', Workspaces)
}
public get catalogGraphQL() {
return this.getOrSet('catalogGraphQL', CatalogGraphQL)
}
public get janusCatalogSystem() {
return this.getOrSet('janusCatalogSystem', Catalog)
}
public get paymentProvider() {
return this.getOrSet('paymentProvider', PaymentProvider)
}
protected getOrSet<TClient extends IOClientConstructor>(key: string, Implementation: TClient): InstanceType<TClient> {
const options = {
...this.clientOptions.default,
...this.clientOptions[key],
metrics,
}
if (!this.clients[key]) {
this.clients[key] = new Implementation(this.ctx, options)
}
return this.clients[key] as InstanceType<TClient>
}
}