-
Notifications
You must be signed in to change notification settings - Fork 2
/
server-api.ts
55 lines (47 loc) · 1.7 KB
/
server-api.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
import { GRPCServiceOptions } from "~/app/core/server/common";
import { getConfig } from "~/app/core/config";
import { GRPCAuthInterceptor } from "~/app/core/auth";
import { DevicesApiAdapter } from "./devices";
import { PatientsApiAdapter } from "./patients";
import { TherapistsApiAdapter } from "./therapists";
import { UploadsApiAdapter } from "./uploads";
import { GRPCDeadlineInterceptor } from "~/app/core/server/grpc-deadline-interceptor";
export interface ServerApiClient {
devices: DevicesApiAdapter;
patients: PatientsApiAdapter;
therapists: TherapistsApiAdapter;
uploads: UploadsApiAdapter;
}
class ServerApiAdapter implements ServerApiClient {
get devices() {
return this.devicesAdapter;
}
get patients() {
return this.patientsAdapter;
}
get therapists() {
return this.therapistsAdapter;
}
get uploads() {
return this.uploadsAdapter;
}
private readonly devicesAdapter: DevicesApiAdapter;
private readonly patientsAdapter: PatientsApiAdapter;
private readonly therapistsAdapter: TherapistsApiAdapter;
private readonly uploadsAdapter: UploadsApiAdapter;
constructor(url: string, options: GRPCServiceOptions) {
this.devicesAdapter = new DevicesApiAdapter(url, options);
this.patientsAdapter = new PatientsApiAdapter(url, options);
this.therapistsAdapter = new TherapistsApiAdapter(url, options);
this.uploadsAdapter = new UploadsApiAdapter(url, options);
}
}
export const serverApi = new ServerApiAdapter(
`https://${getConfig().serverHostname}`,
{
unaryInterceptors: [
new GRPCAuthInterceptor(),
new GRPCDeadlineInterceptor(),
],
}
);