UNPKG

5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.DiagnosticsResult = exports.DiagnosticsEndpoint = exports.PingResult = exports.PingEndpoint = exports.PingState = exports.EndpointState = void 0;
4/**
5 * Represents the status of an an endpoint in a diagnostics report.
6 *
7 * @category Diagnostics
8 */
9var EndpointState;
10(function (EndpointState) {
11 /**
12 * Indicates the endpoint is disconnected.
13 */
14 EndpointState[EndpointState["Disconnected"] = 0] = "Disconnected";
15 /**
16 * Indicates the endpoint is still connecting.
17 */
18 EndpointState[EndpointState["Connecting"] = 1] = "Connecting";
19 /**
20 * Indicates the endpoint is connected.
21 */
22 EndpointState[EndpointState["Connected"] = 2] = "Connected";
23 /**
24 * Indicates the endpoint is disconnecting.
25 */
26 EndpointState[EndpointState["Disconnecting"] = 3] = "Disconnecting";
27})(EndpointState || (exports.EndpointState = EndpointState = {}));
28/**
29 * Represents the status of an an endpoint in a ping report.
30 */
31var PingState;
32(function (PingState) {
33 /**
34 * Indicates the endpoint was pinged successfully.
35 */
36 PingState[PingState["Ok"] = 0] = "Ok";
37 /**
38 * Indicates the endpoint timed out during the ping.
39 */
40 PingState[PingState["Timeout"] = 1] = "Timeout";
41 /**
42 * Indicates an error occured trying to ping the endpoint.
43 */
44 PingState[PingState["Error"] = 2] = "Error";
45})(PingState || (exports.PingState = PingState = {}));
46/**
47 * PingEndpoint represents a single endpoint in a ping result.
48 *
49 * @category Diagnostics
50 */
51class PingEndpoint {
52 /**
53 * @internal
54 */
55 constructor(data) {
56 this.type = data.type;
57 this.id = data.id;
58 this.latency = data.latency;
59 this.remote = data.remote;
60 this.local = data.local;
61 this.state = data.state;
62 this.bucket = data.bucket;
63 this.error = data.error;
64 }
65}
66exports.PingEndpoint = PingEndpoint;
67/**
68 * PingResult represents the output of a ping operation.
69 *
70 * @category Diagnostics
71 */
72class PingResult {
73 /**
74 * @internal
75 */
76 constructor(data) {
77 this.version = data.version;
78 this.id = data.id;
79 this.sdk = data.sdk;
80 this.services = data.services;
81 }
82 /**
83 * Returns a JSON formatted ping report.
84 */
85 toJSON() {
86 return {
87 version: this.version,
88 id: this.id,
89 sdk: this.sdk,
90 services: Object.fromEntries(Object.entries(this.services).map(([serviceType, services]) => {
91 return [
92 serviceType,
93 services.map((svc) => {
94 return {
95 latency_us: svc.latency * 1000000,
96 remote: svc.remote,
97 local: svc.local,
98 id: svc.id,
99 state: svc.state, // state enum is already a string
100 namespace: svc.bucket,
101 error: svc.error,
102 };
103 }),
104 ];
105 })),
106 };
107 }
108}
109exports.PingResult = PingResult;
110/**
111 * DiagnosticsEndpoint represents a single endpoint in a diagnostics
112 * result.
113 *
114 * @category Diagnostics
115 */
116class DiagnosticsEndpoint {
117 /**
118 * @internal
119 */
120 constructor(data) {
121 this.type = data.type;
122 this.id = data.id;
123 this.local = data.local;
124 this.remote = data.remote;
125 this.lastActivity = data.lastActivity;
126 this.state = data.state;
127 }
128}
129exports.DiagnosticsEndpoint = DiagnosticsEndpoint;
130/**
131 * DiagnosticsResult represents the output of a operation result.
132 *
133 * @category Diagnostics
134 */
135class DiagnosticsResult {
136 /**
137 * @internal
138 */
139 constructor(data) {
140 this.version = data.version;
141 this.id = data.id;
142 this.sdk = data.sdk;
143 this.services = data.services;
144 }
145 /**
146 * Returns a JSON formatted diagnostics report.
147 */
148 toJSON() {
149 return {
150 version: this.version,
151 id: this.id,
152 sdk: this.sdk,
153 services: Object.fromEntries(Object.entries(this.services).map(([serviceType, services]) => {
154 return [
155 serviceType,
156 services.map((svc) => {
157 return {
158 last_activity_us: svc.lastActivity * 1000000,
159 remote: svc.remote,
160 local: svc.local,
161 id: svc.id,
162 state: svc.state, // state enum is already a string
163 namespace: svc.bucket,
164 details: svc.details,
165 };
166 }),
167 ];
168 })),
169 };
170 }
171}
172exports.DiagnosticsResult = DiagnosticsResult;