1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.PingExecutor = exports.DiagnoticsExecutor = void 0;
|
4 |
|
5 | const bindingutilities_1 = require("./bindingutilities");
|
6 | const diagnosticstypes_1 = require("./diagnosticstypes");
|
7 |
|
8 |
|
9 |
|
10 | class DiagnoticsExecutor {
|
11 | |
12 |
|
13 |
|
14 | constructor(cluster) {
|
15 | this._cluster = cluster;
|
16 | }
|
17 | |
18 |
|
19 |
|
20 | async diagnostics(options) {
|
21 | return new Promise((resolve, reject) => {
|
22 | this._cluster.conn.diagnostics({
|
23 | report_id: options.reportId,
|
24 | }, (cppErr, resp) => {
|
25 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
26 | if (err || !resp) {
|
27 | reject(err);
|
28 | return;
|
29 | }
|
30 | resolve(new diagnosticstypes_1.DiagnosticsResult({
|
31 | version: resp.version,
|
32 | id: resp.id,
|
33 | sdk: resp.sdk,
|
34 | services: Object.fromEntries(Object.entries(resp.services).map(([serviceType, services]) => {
|
35 | return [
|
36 | (0, bindingutilities_1.serviceTypeFromCpp)(parseInt(serviceType)),
|
37 | services.map((svc) => {
|
38 | return new diagnosticstypes_1.DiagnosticsEndpoint({
|
39 | type: (0, bindingutilities_1.serviceTypeFromCpp)(svc.type),
|
40 | id: svc.id,
|
41 | local: svc.local,
|
42 | remote: svc.remote,
|
43 | lastActivity: svc.last_activity,
|
44 | state: (0, bindingutilities_1.endpointStateFromCpp)(svc.state),
|
45 | });
|
46 | }),
|
47 | ];
|
48 | })),
|
49 | }));
|
50 | });
|
51 | });
|
52 | }
|
53 | }
|
54 | exports.DiagnoticsExecutor = DiagnoticsExecutor;
|
55 |
|
56 |
|
57 |
|
58 | class PingExecutor {
|
59 | |
60 |
|
61 |
|
62 | constructor(cluster) {
|
63 | this._cluster = cluster;
|
64 | }
|
65 | |
66 |
|
67 |
|
68 | async ping(options) {
|
69 | return new Promise((resolve, reject) => {
|
70 |
|
71 | options.timeout;
|
72 | this._cluster.conn.ping({
|
73 | report_id: options.reportId,
|
74 | services: options.serviceTypes
|
75 | ? options.serviceTypes.map((svc) => (0, bindingutilities_1.serviceTypeToCpp)(svc))
|
76 | : undefined,
|
77 | }, (cppErr, resp) => {
|
78 | const err = (0, bindingutilities_1.errorFromCpp)(cppErr);
|
79 | if (err || !resp) {
|
80 | reject(err);
|
81 | return;
|
82 | }
|
83 | resolve(new diagnosticstypes_1.PingResult({
|
84 | version: resp.version,
|
85 | id: resp.id,
|
86 | sdk: resp.sdk,
|
87 | services: Object.fromEntries(Object.entries(resp.services).map(([serviceType, services]) => {
|
88 | return [
|
89 | (0, bindingutilities_1.serviceTypeFromCpp)(parseInt(serviceType)),
|
90 | services.map((svc) => {
|
91 | return new diagnosticstypes_1.PingEndpoint({
|
92 | type: (0, bindingutilities_1.serviceTypeFromCpp)(svc.type),
|
93 | id: svc.id,
|
94 | latency: svc.latency,
|
95 | remote: svc.remote,
|
96 | local: svc.local,
|
97 | state: (0, bindingutilities_1.pingStateFromCpp)(svc.state),
|
98 | bucket: svc.bucket,
|
99 | error: svc.error,
|
100 | });
|
101 | }),
|
102 | ];
|
103 | })),
|
104 | }));
|
105 | });
|
106 | });
|
107 | }
|
108 | }
|
109 | exports.PingExecutor = PingExecutor;
|