@valkey/valkey-glide 2.4.2 → 2.5.0-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,21 @@ var GlideClusterClientConfiguration;
41
41
  PubSubChannelModes[PubSubChannelModes["Sharded"] = 2] = "Sharded";
42
42
  })(PubSubChannelModes = GlideClusterClientConfiguration.PubSubChannelModes || (GlideClusterClientConfiguration.PubSubChannelModes = {}));
43
43
  })(GlideClusterClientConfiguration || (exports.GlideClusterClientConfiguration = GlideClusterClientConfiguration = {}));
44
+ /**
45
+ * @internal
46
+ * Determines whether a command response is from a single node based on routing.
47
+ *
48
+ * @param isRoutedToSingleNodeByDefault - Whether the command defaults to a single node.
49
+ * @param route - The route option provided by the caller.
50
+ * @returns `true` if the response is from a single node.
51
+ */
52
+ function isSingleNodeRoute(isRoutedToSingleNodeByDefault, route) {
53
+ return (
54
+ // route not given and command is routed by default to a random node
55
+ (!route && isRoutedToSingleNodeByDefault) ||
56
+ // or route is given and it is a single node route
57
+ (Boolean(route) && route !== "allPrimaries" && route !== "allNodes"));
58
+ }
44
59
  /**
45
60
  * @internal
46
61
  * Convert {@link ClusterGlideRecord} to {@link ClusterResponse}.
@@ -51,15 +66,30 @@ var GlideClusterClientConfiguration;
51
66
  * @returns Converted value.
52
67
  */
53
68
  function convertClusterGlideRecord(res, isRoutedToSingleNodeByDefault, route) {
54
- const isSingleNodeResponse =
55
- // route not given and command is routed by default to a random node
56
- (!route && isRoutedToSingleNodeByDefault) ||
57
- // or route is given and it is a single node route
58
- (Boolean(route) && route !== "allPrimaries" && route !== "allNodes");
59
- return isSingleNodeResponse
69
+ return isSingleNodeRoute(isRoutedToSingleNodeByDefault, route)
60
70
  ? res
61
71
  : (0, BaseClient_1.convertGlideRecordToRecord)(res);
62
72
  }
73
+ /**
74
+ * Converts a cluster response by applying a transform function to each node's raw value.
75
+ * Handles both single-node and multi-node routing automatically.
76
+ *
77
+ * @param res - Raw response from Glide core.
78
+ * @param isSingleNode - Whether the response is from a single node.
79
+ * @param transform - A function that transforms the raw value into the desired type.
80
+ * @returns Transformed single value or a record mapping node addresses to transformed values.
81
+ */
82
+ function convertAndParseClusterResponse(res, isSingleNode, transform) {
83
+ if (isSingleNode) {
84
+ return transform(res);
85
+ }
86
+ const record = (0, BaseClient_1.convertGlideRecordToRecord)(res);
87
+ const result = {};
88
+ for (const [node, raw] of Object.entries(record)) {
89
+ result[node] = transform(raw);
90
+ }
91
+ return result;
92
+ }
63
93
  /**
64
94
  * Client used for connection to cluster servers.
65
95
  * Use {@link createClient} to request a client.
@@ -527,6 +557,43 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
527
557
  async clientId(options) {
528
558
  return this.createWritePromise((0, Commands_1.createClientId)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
529
559
  }
560
+ /**
561
+ * Returns information about the current client connection's use
562
+ * of the server assisted client side caching feature.
563
+ *
564
+ * The command will be routed to a random node, unless `route` is provided.
565
+ *
566
+ * @see {@link https://valkey.io/commands/client-trackinginfo/|valkey.io} for details.
567
+ *
568
+ * @param options - (Optional) See {@link RouteOption}.
569
+ * @returns A {@link ClusterResponse} containing tracking info(s) for the client.
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * const info = await client.clientTrackingInfo();
574
+ * console.log(info.flags); // Set { "off" }
575
+ * console.log(info.redirect); // -1
576
+ * ```
577
+ *
578
+ * @example
579
+ * ```typescript
580
+ * const info = await client.clientTrackingInfo({ route: "allNodes" });
581
+ * // info is Record<string, ClientTrackingInfo>
582
+ * ```
583
+ */
584
+ async clientTrackingInfo(options) {
585
+ return this.createWritePromise((0, Commands_1.createClientTrackingInfo)(), options).then((res) => {
586
+ if (isSingleNodeRoute(true, options?.route)) {
587
+ return (0, Commands_1.parseClientTrackingInfoResponse)((0, BaseClient_1.convertGlideRecordToRecord)(res));
588
+ }
589
+ const record = (0, BaseClient_1.convertGlideRecordToRecord)(res);
590
+ const result = {};
591
+ for (const [node, entry] of Object.entries(record)) {
592
+ result[node] = (0, Commands_1.parseClientTrackingInfoResponse)(entry);
593
+ }
594
+ return result;
595
+ });
596
+ }
530
597
  /**
531
598
  * Reads the configuration parameters of the running server.
532
599
  * Starting from server version 7, command supports multiple parameters.
@@ -1096,6 +1163,178 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1096
1163
  async lastsave(options) {
1097
1164
  return this.createWritePromise((0, Commands_1.createLastSave)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
1098
1165
  }
1166
+ /**
1167
+ * Returns the latency spike time series for the specified event.
1168
+ *
1169
+ * The command will be routed to all primary nodes, unless `route` is provided.
1170
+ *
1171
+ * @see {@link https://valkey.io/commands/latency-history/|valkey.io} for details.
1172
+ *
1173
+ * @param event - The name of the latency event (e.g., `"command"`).
1174
+ * @param options - (Optional) See {@link RouteOption}.
1175
+ * @returns A {@link ClusterResponse} containing array(s) of {@link LatencyEntry} for the event.
1176
+ *
1177
+ * @example
1178
+ * ```typescript
1179
+ * const history = await client.latencyHistory("command");
1180
+ * // history is Record<string, LatencyEntry[]> (multi-node) or LatencyEntry[] (single-node)
1181
+ * ```
1182
+ */
1183
+ async latencyHistory(event, options) {
1184
+ return this.createWritePromise((0, Commands_1.createLatencyHistory)(event), options).then((res) => convertAndParseClusterResponse(res, isSingleNodeRoute(false, options?.route), (raw) => (0, Commands_1.parseLatencyHistoryResponse)(raw)));
1185
+ }
1186
+ /**
1187
+ * Reports the latest latency events logged by the server.
1188
+ *
1189
+ * The command will be routed to all primary nodes, unless `route` is provided.
1190
+ *
1191
+ * @see {@link https://valkey.io/commands/latency-latest/|valkey.io} for details.
1192
+ *
1193
+ * @param options - (Optional) See {@link RouteOption}.
1194
+ * @returns A {@link ClusterResponse} containing array(s) of {@link LatencyEventInfo} for the latest latency events.
1195
+ *
1196
+ * @example
1197
+ * ```typescript
1198
+ * const latest = await client.latencyLatest();
1199
+ * // latest is Record<string, LatencyEventInfo[]> (multi-node) or LatencyEventInfo[] (single-node)
1200
+ * ```
1201
+ */
1202
+ async latencyLatest(options) {
1203
+ return this.createWritePromise((0, Commands_1.createLatencyLatest)(), options).then((res) => convertAndParseClusterResponse(res, isSingleNodeRoute(false, options?.route), (raw) => (0, Commands_1.parseLatencyLatestResponse)(raw)));
1204
+ }
1205
+ /**
1206
+ * Resets the latency spike time series for all or specified events.
1207
+ * If no events are provided, resets the latency spike time series for all events.
1208
+ *
1209
+ * The command will be routed to all primary nodes, unless `route` is provided.
1210
+ *
1211
+ * @see {@link https://valkey.io/commands/latency-reset/|valkey.io} for details.
1212
+ *
1213
+ * @param events - The event names to reset. If not provided, resets all events.
1214
+ * @param options - (Optional) See {@link RouteOption}.
1215
+ * @returns The total number of event time series that were reset across all nodes.
1216
+ *
1217
+ * @example
1218
+ * ```typescript
1219
+ * await client.latencyReset(); // Resets all events
1220
+ * await client.latencyReset(["command"], { route: "allNodes" });
1221
+ * ```
1222
+ */
1223
+ async latencyReset(events, options) {
1224
+ return this.createWritePromise((0, Commands_1.createLatencyReset)(events), options);
1225
+ }
1226
+ /**
1227
+ * Synchronously saves the dataset to disk.
1228
+ *
1229
+ * The command will be routed to all primary nodes, unless `route` is provided.
1230
+ *
1231
+ * @see {@link https://valkey.io/commands/save/|valkey.io} for more details.
1232
+ *
1233
+ * @param options - (Optional) See {@link RouteOption}.
1234
+ * @returns `"OK"`
1235
+ *
1236
+ * @example
1237
+ * ```typescript
1238
+ * const result = await client.save();
1239
+ * console.log(result); // "OK"
1240
+ * ```
1241
+ */
1242
+ async save(options) {
1243
+ return this.createWritePromise((0, Commands_1.createSave)(), {
1244
+ decoder: BaseClient_1.Decoder.String,
1245
+ ...options,
1246
+ });
1247
+ }
1248
+ /**
1249
+ * Asynchronously saves the dataset to disk in the background.
1250
+ *
1251
+ * The command will be routed to all primary nodes, unless `route` is provided.
1252
+ *
1253
+ * @see {@link https://valkey.io/commands/bgsave/|valkey.io} for more details.
1254
+ *
1255
+ * @param options - (Optional) See {@link RouteOption}.
1256
+ * @returns A non-empty status string.
1257
+ *
1258
+ * @example
1259
+ * ```typescript
1260
+ * const result = await client.bgsave();
1261
+ * console.log(result); // "Background saving started"
1262
+ * ```
1263
+ */
1264
+ async bgsave(options) {
1265
+ return this.createWritePromise((0, Commands_1.createBgSave)(), {
1266
+ decoder: BaseClient_1.Decoder.String,
1267
+ ...options,
1268
+ }).then((res) => convertClusterGlideRecord(res, false, options?.route));
1269
+ }
1270
+ /**
1271
+ * Schedules a background save of the database.
1272
+ *
1273
+ * The command will be routed to all primary nodes, unless `route` is provided.
1274
+ *
1275
+ * @see {@link https://valkey.io/commands/bgsave/|valkey.io} for more details.
1276
+ *
1277
+ * @param options - (Optional) See {@link RouteOption}.
1278
+ * @returns A non-empty status string.
1279
+ *
1280
+ * @example
1281
+ * ```typescript
1282
+ * const result = await client.bgsaveSchedule();
1283
+ * console.log(result); // "Background saving scheduled"
1284
+ * ```
1285
+ */
1286
+ async bgsaveSchedule(options) {
1287
+ return this.createWritePromise((0, Commands_1.createBgSave)(["SCHEDULE"]), {
1288
+ decoder: BaseClient_1.Decoder.String,
1289
+ ...options,
1290
+ }).then((res) => convertClusterGlideRecord(res, false, options?.route));
1291
+ }
1292
+ /**
1293
+ * Aborts all in-progress and scheduled background saves.
1294
+ *
1295
+ * The command will be routed to all primary nodes, unless `route` is provided.
1296
+ *
1297
+ * @see {@link https://valkey.io/commands/bgsave/|valkey.io} for more details.
1298
+ *
1299
+ * @since Valkey 8.1
1300
+ *
1301
+ * @param options - (Optional) See {@link RouteOption}.
1302
+ * @returns A non-empty status string.
1303
+ *
1304
+ * @example
1305
+ * ```typescript
1306
+ * const result = await client.bgsaveCancel();
1307
+ * console.log(result); // "Background saving cancelled"
1308
+ * ```
1309
+ */
1310
+ async bgsaveCancel(options) {
1311
+ return this.createWritePromise((0, Commands_1.createBgSave)(["CANCEL"]), {
1312
+ decoder: BaseClient_1.Decoder.String,
1313
+ ...options,
1314
+ }).then((res) => convertClusterGlideRecord(res, false, options?.route));
1315
+ }
1316
+ /**
1317
+ * Initiates a background rewrite of the append-only file (AOF).
1318
+ *
1319
+ * The command will be routed to all primary nodes, unless `route` is provided.
1320
+ *
1321
+ * @see {@link https://valkey.io/commands/bgrewriteaof/|valkey.io} for more details.
1322
+ *
1323
+ * @param options - (Optional) See {@link RouteOption}.
1324
+ * @returns A non-empty status string.
1325
+ *
1326
+ * @example
1327
+ * ```typescript
1328
+ * const result = await client.bgrewriteaof();
1329
+ * console.log(result); // "Background append only file rewriting started"
1330
+ * ```
1331
+ */
1332
+ async bgrewriteaof(options) {
1333
+ return this.createWritePromise((0, Commands_1.createBgRewriteAof)(), {
1334
+ decoder: BaseClient_1.Decoder.String,
1335
+ ...options,
1336
+ }).then((res) => convertClusterGlideRecord(res, false, options?.route));
1337
+ }
1099
1338
  /**
1100
1339
  * Returns a random existing key name.
1101
1340
  *
@@ -1138,6 +1377,59 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1138
1377
  ...options,
1139
1378
  });
1140
1379
  }
1380
+ /**
1381
+ * Suspends all clients for the specified timeout.
1382
+ *
1383
+ * The command will be routed to all primary nodes, unless `route` is provided.
1384
+ *
1385
+ * @see {@link https://valkey.io/commands/client-pause/|valkey.io} for details.
1386
+ *
1387
+ * @param timeout - The time in milliseconds to pause clients.
1388
+ * @param mode - (Optional) The pause mode to use.
1389
+ * + If not provided, all commands are paused.
1390
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
1391
+ * @returns `"OK"` response on success.
1392
+ *
1393
+ * @example
1394
+ * ```typescript
1395
+ * const result = await client.clientPause(1000);
1396
+ * console.log(result); // Output: 'OK'
1397
+ * ```
1398
+ *
1399
+ * @example
1400
+ * ```typescript
1401
+ * const result = await client.clientPause(1000, ClientPauseMode.WRITE);
1402
+ * console.log(result); // Output: 'OK'
1403
+ * ```
1404
+ */
1405
+ async clientPause(timeout, mode, options) {
1406
+ return this.createWritePromise((0, Commands_1.createClientPause)(timeout, mode), {
1407
+ route: "allPrimaries",
1408
+ ...options,
1409
+ });
1410
+ }
1411
+ /**
1412
+ * Resumes processing commands on all clients.
1413
+ *
1414
+ * The command will be routed to all primary nodes, unless `route` is provided.
1415
+ *
1416
+ * @see {@link https://valkey.io/commands/client-unpause/|valkey.io} for details.
1417
+ *
1418
+ * @param options - (Optional) See {@link RouteOption} and {@link DecoderOption}.
1419
+ * @returns `"OK"` response on success.
1420
+ *
1421
+ * @example
1422
+ * ```typescript
1423
+ * const result = await client.clientUnpause();
1424
+ * console.log(result); // Output: 'OK'
1425
+ * ```
1426
+ */
1427
+ async clientUnpause(options) {
1428
+ return this.createWritePromise((0, Commands_1.createClientUnpause)(), {
1429
+ route: "allPrimaries",
1430
+ ...options,
1431
+ });
1432
+ }
1141
1433
  /**
1142
1434
  * Invokes a Lua script with arguments.
1143
1435
  * This method simplifies the process of invoking scripts on a Valkey server by using an object that represents a Lua script.
@@ -1357,5 +1649,87 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1357
1649
  const response = await this.createWritePromise((0, Commands_1.createGetSubscriptions)());
1358
1650
  return this.parseGetSubscriptionsResponse(response);
1359
1651
  }
1652
+ // TODO #6166: move to shared base once server management refactor lands
1653
+ /**
1654
+ * Returns a report about memory problems detected by the server.
1655
+ *
1656
+ * The command will be routed to all primary nodes, unless `route` is provided.
1657
+ *
1658
+ * @see {@link https://valkey.io/commands/memory-doctor/|valkey.io} for details.
1659
+ *
1660
+ * @param options - (Optional) See {@link RouteOption} to specify the route to override the default.
1661
+ * @returns A {@link ClusterResponse} containing the memory diagnostic report string(s).
1662
+ *
1663
+ * @example
1664
+ * ```typescript
1665
+ * const report = await client.memoryDoctor();
1666
+ * // report is Record<string, string> (multi-node) or string (single-node)
1667
+ * ```
1668
+ */
1669
+ async memoryDoctor(options) {
1670
+ return this.createWritePromise((0, Commands_1.createMemoryDoctor)(), { decoder: BaseClient_1.Decoder.String, ...options }).then((res) => convertClusterGlideRecord(res, false, options?.route));
1671
+ }
1672
+ /**
1673
+ * Returns the internal statistics of the memory allocator.
1674
+ *
1675
+ * The command will be routed to all primary nodes, unless `route` is provided.
1676
+ *
1677
+ * @see {@link https://valkey.io/commands/memory-malloc-stats/|valkey.io} for details.
1678
+ *
1679
+ * @param options - (Optional) See {@link RouteOption} to specify the route to override the default.
1680
+ * @returns A {@link ClusterResponse} containing the memory allocator statistics string(s).
1681
+ *
1682
+ * @example
1683
+ * ```typescript
1684
+ * const stats = await client.memoryMallocStats();
1685
+ * // stats is Record<string, string> (multi-node) or string (single-node)
1686
+ * ```
1687
+ */
1688
+ async memoryMallocStats(options) {
1689
+ return this.createWritePromise((0, Commands_1.createMemoryMallocStats)(), { decoder: BaseClient_1.Decoder.String, ...options }).then((res) => convertClusterGlideRecord(res, false, options?.route));
1690
+ }
1691
+ /**
1692
+ * Asks the server to reclaim memory from the allocator back to the operating system.
1693
+ *
1694
+ * The command will be routed to all primary nodes, unless `route` is provided.
1695
+ *
1696
+ * @see {@link https://valkey.io/commands/memory-purge/|valkey.io} for details.
1697
+ *
1698
+ * @param options - (Optional) See {@link RouteOption} to specify the route to override the default.
1699
+ * @returns `"OK"`.
1700
+ *
1701
+ * @example
1702
+ * ```typescript
1703
+ * const result = await client.memoryPurge();
1704
+ * console.log(result); // Output: 'OK'
1705
+ * ```
1706
+ */
1707
+ async memoryPurge(options) {
1708
+ return this.createWritePromise((0, Commands_1.createMemoryPurge)(), {
1709
+ decoder: BaseClient_1.Decoder.String,
1710
+ ...options,
1711
+ });
1712
+ }
1713
+ /**
1714
+ * Returns detailed memory consumption statistics of the server.
1715
+ *
1716
+ * The command will be routed to all primary nodes, unless `route` is provided.
1717
+ *
1718
+ * @see {@link https://valkey.io/commands/memory-stats/|valkey.io} for details.
1719
+ *
1720
+ * @param options - (Optional) See {@link RouteOption} to specify the route to override the default.
1721
+ * @returns A {@link ClusterResponse} containing {@link MemoryStats} object(s).
1722
+ *
1723
+ * @example
1724
+ * ```typescript
1725
+ * const stats = await client.memoryStats();
1726
+ * // stats is Record<string, MemoryStats> (multi-node) or MemoryStats (single-node)
1727
+ * ```
1728
+ */
1729
+ async memoryStats(options) {
1730
+ return this.createWritePromise((0, Commands_1.createMemoryStats)(), options).then((res) => convertAndParseClusterResponse(res, isSingleNodeRoute(false, options?.route), (raw) => (0, Commands_1.parseMemoryStatsResponse)((0, BaseClient_1.isGlideRecord)(raw)
1731
+ ? (0, BaseClient_1.convertGlideRecordToRecord)(raw)
1732
+ : raw)));
1733
+ }
1360
1734
  }
1361
1735
  exports.GlideClusterClient = GlideClusterClient;
@@ -0,0 +1,36 @@
1
+ import { BaseClientConfiguration } from "./BaseClient.js";
2
+ export interface MonitorLine {
3
+ timestamp: number;
4
+ db: number;
5
+ clientAddr: string;
6
+ command: string;
7
+ args: string[];
8
+ }
9
+ export declare class GlideMonitorClient {
10
+ private handleId;
11
+ private closed;
12
+ private readonly queue;
13
+ private waiters;
14
+ private constructor();
15
+ /**
16
+ * Creates a GlideMonitorClient that streams server-side commands.
17
+ * @param options - Connection configuration.
18
+ * @param callback - Optional callback invoked for each monitor line.
19
+ * If omitted, use {@link getNextMessage} or {@link tryGetNextMessage} to poll.
20
+ */
21
+ static create(options: BaseClientConfiguration, callback?: (line: MonitorLine) => void): Promise<GlideMonitorClient>;
22
+ /**
23
+ * Returns the next monitor line, waiting until one arrives.
24
+ * Only usable when no callback was provided to {@link create}.
25
+ * Rejects if the client is already closed.
26
+ */
27
+ getNextMessage(): Promise<MonitorLine>;
28
+ /**
29
+ * Returns the next monitor line immediately, or `undefined` if none is queued.
30
+ * Only usable when no callback was provided to {@link create}.
31
+ */
32
+ tryGetNextMessage(): MonitorLine | undefined;
33
+ /** Stops monitoring. Idempotent — safe to call multiple times. */
34
+ close(): Promise<void>;
35
+ private static buildConnectionRequest;
36
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ // Copyright Valkey GLIDE Project Contributors - SPDX-Identifier: Apache-2.0
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.GlideMonitorClient = void 0;
5
+ const native_1 = require("../build-ts/native");
6
+ const ProtobufMessage_1 = require("../build-ts/ProtobufMessage");
7
+ class GlideMonitorClient {
8
+ handleId = null;
9
+ closed = false;
10
+ queue = [];
11
+ waiters = [];
12
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
13
+ constructor() { }
14
+ /**
15
+ * Creates a GlideMonitorClient that streams server-side commands.
16
+ * @param options - Connection configuration.
17
+ * @param callback - Optional callback invoked for each monitor line.
18
+ * If omitted, use {@link getNextMessage} or {@link tryGetNextMessage} to poll.
19
+ */
20
+ static async create(options, callback) {
21
+ const client = new GlideMonitorClient();
22
+ const request = GlideMonitorClient.buildConnectionRequest(options);
23
+ const bytes = ProtobufMessage_1.connection_request.ConnectionRequest.encode(request).finish();
24
+ client.handleId = await (0, native_1.createMonitorClient)(Buffer.from(bytes), (timestamp, db, clientAddr, command, args) => {
25
+ const line = {
26
+ timestamp,
27
+ db,
28
+ clientAddr,
29
+ command,
30
+ args,
31
+ };
32
+ if (callback) {
33
+ callback(line);
34
+ }
35
+ else {
36
+ const waiter = client.waiters.shift();
37
+ if (waiter) {
38
+ waiter.resolve(line);
39
+ }
40
+ else {
41
+ client.queue.push(line);
42
+ }
43
+ }
44
+ });
45
+ return client;
46
+ }
47
+ /**
48
+ * Returns the next monitor line, waiting until one arrives.
49
+ * Only usable when no callback was provided to {@link create}.
50
+ * Rejects if the client is already closed.
51
+ */
52
+ getNextMessage() {
53
+ if (this.closed) {
54
+ return Promise.reject(new Error("Monitor is closed"));
55
+ }
56
+ if (this.queue.length > 0) {
57
+ return Promise.resolve(this.queue.shift());
58
+ }
59
+ return new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
60
+ }
61
+ /**
62
+ * Returns the next monitor line immediately, or `undefined` if none is queued.
63
+ * Only usable when no callback was provided to {@link create}.
64
+ */
65
+ tryGetNextMessage() {
66
+ return this.queue.shift();
67
+ }
68
+ /** Stops monitoring. Idempotent — safe to call multiple times. */
69
+ async close() {
70
+ if (this.closed)
71
+ return;
72
+ this.closed = true;
73
+ // Reject any pending getNextMessage() waiters so callers don't hang.
74
+ for (const { reject } of this.waiters.splice(0)) {
75
+ reject(new Error("Monitor is closed"));
76
+ }
77
+ if (this.handleId !== null) {
78
+ const id = this.handleId;
79
+ this.handleId = null;
80
+ await (0, native_1.closeMonitorClient)(id);
81
+ }
82
+ }
83
+ static buildConnectionRequest(options) {
84
+ return ProtobufMessage_1.connection_request.ConnectionRequest.create({
85
+ addresses: options.addresses?.map((a) => ({
86
+ host: a.host,
87
+ port: a.port,
88
+ })),
89
+ tlsMode: options.useTLS
90
+ ? ProtobufMessage_1.connection_request.TlsMode.SecureTls
91
+ : ProtobufMessage_1.connection_request.TlsMode.NoTls,
92
+ authenticationInfo: options.credentials != null && "password" in options.credentials
93
+ ? ProtobufMessage_1.connection_request.AuthenticationInfo.create({
94
+ username: options.credentials.username ?? "",
95
+ password: options.credentials.password,
96
+ })
97
+ : undefined,
98
+ databaseId: options.databaseId ?? 0,
99
+ clientName: options.clientName,
100
+ });
101
+ }
102
+ }
103
+ exports.GlideMonitorClient = GlideMonitorClient;