@valkey/valkey-glide 1.3.5-rc9 → 2.0.0-rc7

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.
@@ -1,10 +1,7 @@
1
1
  /**
2
2
  * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
3
  */
4
- import { AdvancedBaseClientConfiguration, BaseClient, BaseClientConfiguration, DecoderOption, GlideReturnType, GlideString, PubSubMsg } from "./BaseClient";
5
- import { ClusterBatch } from "./Batch";
6
- import { ClusterBatchOptions, ClusterScanOptions, FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsSingleResponse, InfoOptions, LolwutOptions } from "./Commands";
7
- import { ClusterScanCursor, Script } from "./native";
4
+ import { AdvancedBaseClientConfiguration, BaseClient, BaseClientConfiguration, ClusterBatch, ClusterBatchOptions, ClusterScanCursor, ClusterScanOptions, DecoderOption, FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsSingleResponse, GlideReturnType, GlideString, InfoOptions, LolwutOptions, PubSubMsg, Script } from ".";
8
5
  /** An extension to command option types with {@link Routes}. */
9
6
  export interface RouteOption {
10
7
  /**
@@ -134,6 +131,9 @@ export type GlideClusterClientConfiguration = BaseClientConfiguration & {
134
131
  * ```typescript
135
132
  * const config: AdvancedGlideClusterClientConfiguration = {
136
133
  * connectionTimeout: 500, // Set the connection timeout to 500ms
134
+ * tlsAdvancedConfiguration: {
135
+ * insecure: true, // Skip TLS certificate verification (use only in development)
136
+ * },
137
137
  * };
138
138
  * ```
139
139
  */
@@ -425,6 +425,12 @@ export declare class GlideClusterClient extends BaseClient {
425
425
  * console.log(`Received message: ${msg.payload}`);
426
426
  * },
427
427
  * },
428
+ * connectionBackoff: {
429
+ * numberOfRetries: 5,
430
+ * factor: 1000,
431
+ * exponentBase: 2,
432
+ * jitter: 20,
433
+ * },
428
434
  * });
429
435
  * ```
430
436
  *
@@ -432,6 +438,8 @@ export declare class GlideClusterClient extends BaseClient {
432
438
  * - **Cluster Topology Discovery**: The client will automatically discover the cluster topology based on the seed addresses provided.
433
439
  * - **Authentication**: If `credentials` are provided, the client will attempt to authenticate using the specified username and password.
434
440
  * - **TLS**: If `useTLS` is set to `true`, the client will establish secure connections using TLS.
441
+ * Should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail.
442
+ * For advanced tls configuration, please use the {@link AdvancedGlideClusterClientConfiguration} option.
435
443
  * - **Periodic Checks**: The `periodicChecks` setting allows you to configure how often the client checks for cluster topology changes.
436
444
  * - **Pub/Sub Subscriptions**: Any channels or patterns specified in `pubsubSubscriptions` will be subscribed to upon connection.
437
445
  */
@@ -4,10 +4,8 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.GlideClusterClient = exports.GlideClusterClientConfiguration = void 0;
7
+ const _1 = require(".");
7
8
  const ProtobufMessage_1 = require("../build-ts/ProtobufMessage");
8
- const BaseClient_1 = require("./BaseClient");
9
- const Commands_1 = require("./Commands");
10
- const native_1 = require("./native");
11
9
  /* eslint-disable-next-line @typescript-eslint/no-namespace */
12
10
  var GlideClusterClientConfiguration;
13
11
  (function (GlideClusterClientConfiguration) {
@@ -48,7 +46,7 @@ function convertClusterGlideRecord(res, isRoutedToSingleNodeByDefault, route) {
48
46
  (Boolean(route) && route !== "allPrimaries" && route !== "allNodes");
49
47
  return isSingleNodeResponse
50
48
  ? res
51
- : (0, BaseClient_1.convertGlideRecordToRecord)(res);
49
+ : (0, _1.convertGlideRecordToRecord)(res);
52
50
  }
53
51
  /**
54
52
  * Client used for connection to cluster servers.
@@ -56,7 +54,7 @@ function convertClusterGlideRecord(res, isRoutedToSingleNodeByDefault, route) {
56
54
  *
57
55
  * @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#cluster | Valkey Glide Wiki}.
58
56
  */
59
- class GlideClusterClient extends BaseClient_1.BaseClient {
57
+ class GlideClusterClient extends _1.BaseClient {
60
58
  /**
61
59
  * @internal
62
60
  */
@@ -120,6 +118,12 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
120
118
  * console.log(`Received message: ${msg.payload}`);
121
119
  * },
122
120
  * },
121
+ * connectionBackoff: {
122
+ * numberOfRetries: 5,
123
+ * factor: 1000,
124
+ * exponentBase: 2,
125
+ * jitter: 20,
126
+ * },
123
127
  * });
124
128
  * ```
125
129
  *
@@ -127,6 +131,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
127
131
  * - **Cluster Topology Discovery**: The client will automatically discover the cluster topology based on the seed addresses provided.
128
132
  * - **Authentication**: If `credentials` are provided, the client will attempt to authenticate using the specified username and password.
129
133
  * - **TLS**: If `useTLS` is set to `true`, the client will establish secure connections using TLS.
134
+ * Should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail.
135
+ * For advanced tls configuration, please use the {@link AdvancedGlideClusterClientConfiguration} option.
130
136
  * - **Periodic Checks**: The `periodicChecks` setting allows you to configure how often the client checks for cluster topology changes.
131
137
  * - **Pub/Sub Subscriptions**: Any channels or patterns specified in `pubsubSubscriptions` will be subscribed to upon connection.
132
138
  */
@@ -175,7 +181,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
175
181
  (resolveAns) => {
176
182
  try {
177
183
  resolve([
178
- new native_1.ClusterScanCursor(resolveAns[0].toString()),
184
+ new _1.ClusterScanCursor(resolveAns[0].toString()),
179
185
  resolveAns[1],
180
186
  ]);
181
187
  }
@@ -277,7 +283,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
277
283
  * ```
278
284
  */
279
285
  async customCommand(args, options) {
280
- const command = (0, Commands_1.createCustomCommand)(args);
286
+ const command = (0, _1.createCustomCommand)(args);
281
287
  return super.createWritePromise(command, options);
282
288
  }
283
289
  /**
@@ -374,7 +380,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
374
380
  * ```
375
381
  */
376
382
  async ping(options) {
377
- return this.createWritePromise((0, Commands_1.createPing)(options?.message), options);
383
+ return this.createWritePromise((0, _1.createPing)(options?.message), options);
378
384
  }
379
385
  /**
380
386
  * Gets information and statistics about the server.
@@ -401,7 +407,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
401
407
  * ```
402
408
  */
403
409
  async info(options) {
404
- return this.createWritePromise((0, Commands_1.createInfo)(options?.sections), { decoder: BaseClient_1.Decoder.String, ...options }).then((res) => convertClusterGlideRecord(res, false, options?.route));
410
+ return this.createWritePromise((0, _1.createInfo)(options?.sections), { decoder: _1.Decoder.String, ...options }).then((res) => convertClusterGlideRecord(res, false, options?.route));
405
411
  }
406
412
  /**
407
413
  * Gets the name of the connection to which the request is routed.
@@ -431,7 +437,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
431
437
  * ```
432
438
  */
433
439
  async clientGetName(options) {
434
- return this.createWritePromise((0, Commands_1.createClientGetName)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
440
+ return this.createWritePromise((0, _1.createClientGetName)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
435
441
  }
436
442
  /**
437
443
  * Rewrites the configuration file with the current configuration.
@@ -451,8 +457,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
451
457
  * ```
452
458
  */
453
459
  async configRewrite(options) {
454
- return this.createWritePromise((0, Commands_1.createConfigRewrite)(), {
455
- decoder: BaseClient_1.Decoder.String,
460
+ return this.createWritePromise((0, _1.createConfigRewrite)(), {
461
+ decoder: _1.Decoder.String,
456
462
  ...options,
457
463
  });
458
464
  }
@@ -474,8 +480,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
474
480
  * ```
475
481
  */
476
482
  async configResetStat(options) {
477
- return this.createWritePromise((0, Commands_1.createConfigResetStat)(), {
478
- decoder: BaseClient_1.Decoder.String,
483
+ return this.createWritePromise((0, _1.createConfigResetStat)(), {
484
+ decoder: _1.Decoder.String,
479
485
  ...options,
480
486
  });
481
487
  }
@@ -497,7 +503,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
497
503
  * ```
498
504
  */
499
505
  async clientId(options) {
500
- return this.createWritePromise((0, Commands_1.createClientId)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
506
+ return this.createWritePromise((0, _1.createClientId)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
501
507
  }
502
508
  /**
503
509
  * Reads the configuration parameters of the running server.
@@ -528,7 +534,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
528
534
  * ```
529
535
  */
530
536
  async configGet(parameters, options) {
531
- return this.createWritePromise((0, Commands_1.createConfigGet)(parameters), options).then((res) => (0, BaseClient_1.convertGlideRecordToRecord)(res));
537
+ return this.createWritePromise((0, _1.createConfigGet)(parameters), options).then((res) => (0, _1.convertGlideRecordToRecord)(res));
532
538
  }
533
539
  /**
534
540
  * Sets configuration parameters to the specified values.
@@ -550,8 +556,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
550
556
  * ```
551
557
  */
552
558
  async configSet(parameters, options) {
553
- return this.createWritePromise((0, Commands_1.createConfigSet)(parameters), {
554
- decoder: BaseClient_1.Decoder.String,
559
+ return this.createWritePromise((0, _1.createConfigSet)(parameters), {
560
+ decoder: _1.Decoder.String,
555
561
  ...options,
556
562
  });
557
563
  }
@@ -581,7 +587,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
581
587
  * ```
582
588
  */
583
589
  async echo(message, options) {
584
- return this.createWritePromise((0, Commands_1.createEcho)(message), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
590
+ return this.createWritePromise((0, _1.createEcho)(message), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
585
591
  }
586
592
  /**
587
593
  * Returns the server time.
@@ -614,7 +620,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
614
620
  * ```
615
621
  */
616
622
  async time(options) {
617
- return this.createWritePromise((0, Commands_1.createTime)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
623
+ return this.createWritePromise((0, _1.createTime)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
618
624
  }
619
625
  /**
620
626
  * Copies the value stored at the `source` to the `destination` key. When `replace` is `true`,
@@ -638,7 +644,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
638
644
  * ```
639
645
  */
640
646
  async copy(source, destination, options) {
641
- return this.createWritePromise((0, Commands_1.createCopy)(source, destination, options));
647
+ return this.createWritePromise((0, _1.createCopy)(source, destination, options));
642
648
  }
643
649
  /**
644
650
  * Displays a piece of generative computer art and the server version.
@@ -657,7 +663,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
657
663
  * ```
658
664
  */
659
665
  async lolwut(options) {
660
- return this.createWritePromise((0, Commands_1.createLolwut)(options), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
666
+ return this.createWritePromise((0, _1.createLolwut)(options), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
661
667
  }
662
668
  /**
663
669
  * Invokes a previously loaded function.
@@ -679,7 +685,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
679
685
  * ```
680
686
  */
681
687
  async fcallWithRoute(func, args, options) {
682
- return this.createWritePromise((0, Commands_1.createFCall)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
688
+ return this.createWritePromise((0, _1.createFCall)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
683
689
  }
684
690
  /**
685
691
  * Invokes a previously loaded read-only function.
@@ -702,7 +708,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
702
708
  * ```
703
709
  */
704
710
  async fcallReadonlyWithRoute(func, args, options) {
705
- return this.createWritePromise((0, Commands_1.createFCallReadOnly)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
711
+ return this.createWritePromise((0, _1.createFCallReadOnly)(func, [], args), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
706
712
  }
707
713
  /**
708
714
  * Deletes a library and all its functions.
@@ -722,8 +728,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
722
728
  * ```
723
729
  */
724
730
  async functionDelete(libraryCode, options) {
725
- return this.createWritePromise((0, Commands_1.createFunctionDelete)(libraryCode), {
726
- decoder: BaseClient_1.Decoder.String,
731
+ return this.createWritePromise((0, _1.createFunctionDelete)(libraryCode), {
732
+ decoder: _1.Decoder.String,
727
733
  ...options,
728
734
  });
729
735
  }
@@ -749,7 +755,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
749
755
  * ```
750
756
  */
751
757
  async functionLoad(libraryCode, options) {
752
- return this.createWritePromise((0, Commands_1.createFunctionLoad)(libraryCode, options?.replace), options);
758
+ return this.createWritePromise((0, _1.createFunctionLoad)(libraryCode, options?.replace), options);
753
759
  }
754
760
  /**
755
761
  * Deletes all function libraries.
@@ -769,8 +775,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
769
775
  * ```
770
776
  */
771
777
  async functionFlush(options) {
772
- return this.createWritePromise((0, Commands_1.createFunctionFlush)(options?.mode), {
773
- decoder: BaseClient_1.Decoder.String,
778
+ return this.createWritePromise((0, _1.createFunctionFlush)(options?.mode), {
779
+ decoder: _1.Decoder.String,
774
780
  ...options,
775
781
  });
776
782
  }
@@ -805,13 +811,13 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
805
811
  * ```
806
812
  */
807
813
  async functionList(options) {
808
- return this.createWritePromise((0, Commands_1.createFunctionList)(options), options).then((res) => res.length == 0
814
+ return this.createWritePromise((0, _1.createFunctionList)(options), options).then((res) => res.length == 0
809
815
  ? res // no libs
810
816
  : (Array.isArray(res[0])
811
817
  ? // single node response
812
- res.map(BaseClient_1.convertGlideRecordToRecord)
818
+ res.map(_1.convertGlideRecordToRecord)
813
819
  : // multi node response
814
- (0, BaseClient_1.convertGlideRecordToRecord)(res)));
820
+ (0, _1.convertGlideRecordToRecord)(res)));
815
821
  }
816
822
  /**
817
823
  * Returns information about the function that's currently running and information about the
@@ -863,7 +869,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
863
869
  * ```
864
870
  */
865
871
  async functionStats(options) {
866
- return this.createWritePromise((0, Commands_1.createFunctionStats)(), options).then((res) => (0, BaseClient_1.convertGlideRecordToRecord)(res));
872
+ return this.createWritePromise((0, _1.createFunctionStats)(), options).then((res) => (0, _1.convertGlideRecordToRecord)(res));
867
873
  }
868
874
  /**
869
875
  * Kills a function that is currently executing.
@@ -881,8 +887,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
881
887
  * ```
882
888
  */
883
889
  async functionKill(options) {
884
- return this.createWritePromise((0, Commands_1.createFunctionKill)(), {
885
- decoder: BaseClient_1.Decoder.String,
890
+ return this.createWritePromise((0, _1.createFunctionKill)(), {
891
+ decoder: _1.Decoder.String,
886
892
  ...options,
887
893
  });
888
894
  }
@@ -902,7 +908,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
902
908
  * ```
903
909
  */
904
910
  async functionDump(options) {
905
- return this.createWritePromise((0, Commands_1.createFunctionDump)(), { decoder: BaseClient_1.Decoder.Bytes, ...options }).then((res) => convertClusterGlideRecord(res, true, options?.route));
911
+ return this.createWritePromise((0, _1.createFunctionDump)(), { decoder: _1.Decoder.Bytes, ...options }).then((res) => convertClusterGlideRecord(res, true, options?.route));
906
912
  }
907
913
  /**
908
914
  * Restores libraries from the serialized payload returned by {@link functionDump}.
@@ -923,7 +929,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
923
929
  * ```
924
930
  */
925
931
  async functionRestore(payload, options) {
926
- return this.createWritePromise((0, Commands_1.createFunctionRestore)(payload, options?.policy), { decoder: BaseClient_1.Decoder.String, ...options });
932
+ return this.createWritePromise((0, _1.createFunctionRestore)(payload, options?.policy), { decoder: _1.Decoder.String, ...options });
927
933
  }
928
934
  /**
929
935
  * Deletes all the keys of all the existing databases. This command never fails.
@@ -944,8 +950,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
944
950
  * ```
945
951
  */
946
952
  async flushall(options) {
947
- return this.createWritePromise((0, Commands_1.createFlushAll)(options?.mode), {
948
- decoder: BaseClient_1.Decoder.String,
953
+ return this.createWritePromise((0, _1.createFlushAll)(options?.mode), {
954
+ decoder: _1.Decoder.String,
949
955
  ...options,
950
956
  });
951
957
  }
@@ -968,8 +974,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
968
974
  * ```
969
975
  */
970
976
  async flushdb(options) {
971
- return this.createWritePromise((0, Commands_1.createFlushDB)(options?.mode), {
972
- decoder: BaseClient_1.Decoder.String,
977
+ return this.createWritePromise((0, _1.createFlushDB)(options?.mode), {
978
+ decoder: _1.Decoder.String,
973
979
  ...options,
974
980
  });
975
981
  }
@@ -991,7 +997,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
991
997
  * ```
992
998
  */
993
999
  async dbsize(options) {
994
- return this.createWritePromise((0, Commands_1.createDBSize)(), options);
1000
+ return this.createWritePromise((0, _1.createDBSize)(), options);
995
1001
  }
996
1002
  /** Publish a message on pubsub channel.
997
1003
  * This command aggregates PUBLISH and SPUBLISH commands functionalities.
@@ -1020,7 +1026,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1020
1026
  * ```
1021
1027
  */
1022
1028
  async publish(message, channel, sharded = false) {
1023
- return this.createWritePromise((0, Commands_1.createPublish)(message, channel, sharded));
1029
+ return this.createWritePromise((0, _1.createPublish)(message, channel, sharded));
1024
1030
  }
1025
1031
  /**
1026
1032
  * Lists the currently active shard channels.
@@ -1045,7 +1051,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1045
1051
  * ```
1046
1052
  */
1047
1053
  async pubsubShardChannels(options) {
1048
- return this.createWritePromise((0, Commands_1.createPubsubShardChannels)(options?.pattern), options);
1054
+ return this.createWritePromise((0, _1.createPubsubShardChannels)(options?.pattern), options);
1049
1055
  }
1050
1056
  /**
1051
1057
  * Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified shard channels.
@@ -1068,7 +1074,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1068
1074
  * ```
1069
1075
  */
1070
1076
  async pubsubShardNumSub(channels, options) {
1071
- return this.createWritePromise((0, Commands_1.createPubSubShardNumSub)(channels), options).then((res) => res.map((r) => {
1077
+ return this.createWritePromise((0, _1.createPubSubShardNumSub)(channels), options).then((res) => res.map((r) => {
1072
1078
  return { channel: r.key, numSub: r.value };
1073
1079
  }));
1074
1080
  }
@@ -1090,7 +1096,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1090
1096
  * ```
1091
1097
  */
1092
1098
  async lastsave(options) {
1093
- return this.createWritePromise((0, Commands_1.createLastSave)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
1099
+ return this.createWritePromise((0, _1.createLastSave)(), options).then((res) => convertClusterGlideRecord(res, true, options?.route));
1094
1100
  }
1095
1101
  /**
1096
1102
  * Returns a random existing key name.
@@ -1109,7 +1115,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1109
1115
  * ```
1110
1116
  */
1111
1117
  async randomKey(options) {
1112
- return this.createWritePromise((0, Commands_1.createRandomKey)(), options);
1118
+ return this.createWritePromise((0, _1.createRandomKey)(), options);
1113
1119
  }
1114
1120
  /**
1115
1121
  * Flushes all the previously watched keys for a transaction. Executing a transaction will
@@ -1131,8 +1137,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1131
1137
  * ```
1132
1138
  */
1133
1139
  async unwatch(options) {
1134
- return this.createWritePromise((0, Commands_1.createUnWatch)(), {
1135
- decoder: BaseClient_1.Decoder.String,
1140
+ return this.createWritePromise((0, _1.createUnWatch)(), {
1141
+ decoder: _1.Decoder.String,
1136
1142
  ...options,
1137
1143
  });
1138
1144
  }
@@ -1202,7 +1208,7 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1202
1208
  * ```
1203
1209
  */
1204
1210
  async scriptExists(sha1s, options) {
1205
- return this.createWritePromise((0, Commands_1.createScriptExists)(sha1s), options);
1211
+ return this.createWritePromise((0, _1.createScriptExists)(sha1s), options);
1206
1212
  }
1207
1213
  /**
1208
1214
  * Flushes the Lua scripts cache.
@@ -1221,8 +1227,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1221
1227
  * ```
1222
1228
  */
1223
1229
  async scriptFlush(options) {
1224
- return this.createWritePromise((0, Commands_1.createScriptFlush)(options?.mode), {
1225
- decoder: BaseClient_1.Decoder.String,
1230
+ return this.createWritePromise((0, _1.createScriptFlush)(options?.mode), {
1231
+ decoder: _1.Decoder.String,
1226
1232
  ...options,
1227
1233
  });
1228
1234
  }
@@ -1242,8 +1248,8 @@ class GlideClusterClient extends BaseClient_1.BaseClient {
1242
1248
  * ```
1243
1249
  */
1244
1250
  async scriptKill(options) {
1245
- return this.createWritePromise((0, Commands_1.createScriptKill)(), {
1246
- decoder: BaseClient_1.Decoder.String,
1251
+ return this.createWritePromise((0, _1.createScriptKill)(), {
1252
+ decoder: _1.Decoder.String,
1247
1253
  ...options,
1248
1254
  });
1249
1255
  }
@@ -2,31 +2,46 @@
2
2
  * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
3
  */
4
4
  export type LevelOptions = "error" | "warn" | "info" | "debug" | "trace" | "off";
5
+ /**
6
+ * A singleton class that allows logging which is consistent with logs from the internal GLIDE core.
7
+ * The logger can be set up in 2 ways -
8
+ * 1. By calling {@link init}, which configures the logger only if it wasn't previously configured.
9
+ * 2. By calling {@link setLoggerConfig}, which replaces the existing configuration, and means that new logs
10
+ * will not be saved with the logs that were sent before the call. The previous logs will remain unchanged.
11
+ * If none of these functions are called, the first log attempt will initialize a new logger with default configuration.
12
+ */
5
13
  export declare class Logger {
6
14
  private static _instance;
7
15
  private static logger_level;
8
16
  private constructor();
9
17
  /**
10
- * take the arguments from the user and provide to the core-logger (see ../logger-core)
11
- * if the level is higher then the logger level (error is 0, warn 1, etc.) simply return without operation
12
- * if a logger instance doesn't exist, create new one with default mode (decided by rust core, normally - level: error, target: console)
13
- * logIdentifier arg is a string contain data that suppose to give the log a context and make it easier to find certain type of logs.
14
- * when the log is connect to certain task the identifier should be the task id, when the log is not part of specific task the identifier should give a context to the log - for example, "socket connection".
15
- * External users shouldn't use this function.
18
+ * Logs the provided message if the provided log level is lower then the logger level.
19
+ *
20
+ * @param logLevel - The log level of the provided message.
21
+ * @param logIdentifier - The log identifier should give the log a context.
22
+ * @param message - The message to log.
23
+ * @param err - The exception or error to log.
16
24
  */
17
- static log(logLevel: LevelOptions, logIdentifier: string, message: string): void;
25
+ static log(logLevel: LevelOptions, logIdentifier: string, message: string, err?: Error): void;
18
26
  /**
19
- * Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger.
20
- * The logger will filter all logs with a level lower than the given level,
21
- * If given a fileName argument, will write the logs to files postfixed with fileName. If fileName isn't provided, the logs will be written to the console.
22
- * To turn off the logger, provide the level "off".
27
+ * Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to
28
+ * replace an existing logger.
29
+ * The logger will filter all logs with a level lower than the given level.
30
+ * If given a fileName argument, will write the logs to files postfixed with fileName. If fileName isn't provided,
31
+ * the logs will be written to the console.
32
+ *
33
+ * @param level - Set the logger level to one of [ERROR, WARN, INFO, DEBUG, TRACE, OFF].
34
+ * If log level isn't provided, the logger will be configured with default configuration.
35
+ * To turn off logging completely, set the level to level "off".
36
+ * @param fileName - If provided the target of the logs will be the file mentioned.
37
+ * Otherwise, logs will be printed to the console.
23
38
  */
24
39
  static init(level?: LevelOptions, fileName?: string): void;
25
40
  /**
26
- * configure the logger.
27
- * the level argument is the level of the logs you want the system to provide (error logs, warn logs, etc.)
28
- * the filename argument is optional - if provided the target of the logs will be the file mentioned, else will be the console
29
- * To turn off the logger, provide the level "off".
41
+ * Creates a new logger instance and configure it with the provided log level and file name.
42
+ *
43
+ * @param level - Set the logger level to one of [ERROR, WARN, INFO, DEBUG, TRACE, OFF].
44
+ * @param fileName - The target of the logs will be the file mentioned.
30
45
  */
31
46
  static setLoggerConfig(level: LevelOptions, fileName?: string): void;
32
47
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Logger = void 0;
7
- const native_1 = require("./native");
7
+ const _1 = require(".");
8
8
  const LEVEL = new Map([
9
9
  ["error", 0 /* Level.Error */],
10
10
  ["warn", 1 /* Level.Warn */],
@@ -14,39 +14,52 @@ const LEVEL = new Map([
14
14
  ["off", 5 /* Level.Off */],
15
15
  [undefined, undefined],
16
16
  ]);
17
- /*
18
- * A singleton class that allows logging which is consistent with logs from the internal rust core.
17
+ /**
18
+ * A singleton class that allows logging which is consistent with logs from the internal GLIDE core.
19
19
  * The logger can be set up in 2 ways -
20
- * 1. By calling init, which configures the logger only if it wasn't previously configured.
21
- * 2. By calling Logger.setLoggerConfig, which replaces the existing configuration, and means that new logs will not be saved with the logs that were sent before the call. The previous logs will remain unchanged.
22
- * If no call to any of these function is received, the first log attempt will configure the logger with default configuration decided by rust core.
20
+ * 1. By calling {@link init}, which configures the logger only if it wasn't previously configured.
21
+ * 2. By calling {@link setLoggerConfig}, which replaces the existing configuration, and means that new logs
22
+ * will not be saved with the logs that were sent before the call. The previous logs will remain unchanged.
23
+ * If none of these functions are called, the first log attempt will initialize a new logger with default configuration.
23
24
  */
24
25
  class Logger {
26
+ static _instance;
27
+ static logger_level = 0;
25
28
  constructor(level, fileName) {
26
- Logger.logger_level = (0, native_1.InitInternalLogger)(LEVEL.get(level), fileName);
29
+ Logger.logger_level = (0, _1.InitInternalLogger)(LEVEL.get(level), fileName);
27
30
  }
28
31
  /**
29
- * take the arguments from the user and provide to the core-logger (see ../logger-core)
30
- * if the level is higher then the logger level (error is 0, warn 1, etc.) simply return without operation
31
- * if a logger instance doesn't exist, create new one with default mode (decided by rust core, normally - level: error, target: console)
32
- * logIdentifier arg is a string contain data that suppose to give the log a context and make it easier to find certain type of logs.
33
- * when the log is connect to certain task the identifier should be the task id, when the log is not part of specific task the identifier should give a context to the log - for example, "socket connection".
34
- * External users shouldn't use this function.
32
+ * Logs the provided message if the provided log level is lower then the logger level.
33
+ *
34
+ * @param logLevel - The log level of the provided message.
35
+ * @param logIdentifier - The log identifier should give the log a context.
36
+ * @param message - The message to log.
37
+ * @param err - The exception or error to log.
35
38
  */
36
- static log(logLevel, logIdentifier, message) {
39
+ static log(logLevel, logIdentifier, message, err) {
37
40
  if (!Logger._instance) {
38
41
  new Logger();
39
42
  }
43
+ if (err) {
44
+ message += `: ${err.stack}`;
45
+ }
40
46
  const level = LEVEL.get(logLevel) || 0;
41
47
  if (!(level <= Logger.logger_level))
42
48
  return;
43
- (0, native_1.log)(level, logIdentifier, message);
49
+ (0, _1.log)(level, logIdentifier, message);
44
50
  }
45
51
  /**
46
- * Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to replace an existing logger.
47
- * The logger will filter all logs with a level lower than the given level,
48
- * If given a fileName argument, will write the logs to files postfixed with fileName. If fileName isn't provided, the logs will be written to the console.
49
- * To turn off the logger, provide the level "off".
52
+ * Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to
53
+ * replace an existing logger.
54
+ * The logger will filter all logs with a level lower than the given level.
55
+ * If given a fileName argument, will write the logs to files postfixed with fileName. If fileName isn't provided,
56
+ * the logs will be written to the console.
57
+ *
58
+ * @param level - Set the logger level to one of [ERROR, WARN, INFO, DEBUG, TRACE, OFF].
59
+ * If log level isn't provided, the logger will be configured with default configuration.
60
+ * To turn off logging completely, set the level to level "off".
61
+ * @param fileName - If provided the target of the logs will be the file mentioned.
62
+ * Otherwise, logs will be printed to the console.
50
63
  */
51
64
  static init(level, fileName) {
52
65
  if (!this._instance) {
@@ -54,14 +67,13 @@ class Logger {
54
67
  }
55
68
  }
56
69
  /**
57
- * configure the logger.
58
- * the level argument is the level of the logs you want the system to provide (error logs, warn logs, etc.)
59
- * the filename argument is optional - if provided the target of the logs will be the file mentioned, else will be the console
60
- * To turn off the logger, provide the level "off".
70
+ * Creates a new logger instance and configure it with the provided log level and file name.
71
+ *
72
+ * @param level - Set the logger level to one of [ERROR, WARN, INFO, DEBUG, TRACE, OFF].
73
+ * @param fileName - The target of the logs will be the file mentioned.
61
74
  */
62
75
  static setLoggerConfig(level, fileName) {
63
76
  this._instance = new this(level, fileName);
64
77
  }
65
78
  }
66
79
  exports.Logger = Logger;
67
- Logger.logger_level = 0;