UNPKG

4.2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.PingExecutor = exports.DiagnoticsExecutor = void 0;
4/* eslint jsdoc/require-jsdoc: off */
5const bindingutilities_1 = require("./bindingutilities");
6const diagnosticstypes_1 = require("./diagnosticstypes");
7/**
8 * @internal
9 */
10class DiagnoticsExecutor {
11 /**
12 * @internal
13 */
14 constructor(cluster) {
15 this._cluster = cluster;
16 }
17 /**
18 * @internal
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}
54exports.DiagnoticsExecutor = DiagnoticsExecutor;
55/**
56 * @internal
57 */
58class PingExecutor {
59 /**
60 * @internal
61 */
62 constructor(cluster) {
63 this._cluster = cluster;
64 }
65 /**
66 * @internal
67 */
68 async ping(options) {
69 return new Promise((resolve, reject) => {
70 // BUG(JSCBC-993): timeout is not currently sent to the C++ client
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}
109exports.PingExecutor = PingExecutor;