@valkey/valkey-glide 1.3.4 → 1.3.5-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.
Files changed (29) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +36 -14
  3. package/build-ts/{src/BaseClient.d.ts → BaseClient.d.ts} +62 -118
  4. package/build-ts/BaseClient.js +6049 -0
  5. package/build-ts/{src/Transaction.d.ts → Batch.d.ts} +124 -67
  6. package/build-ts/Batch.js +3457 -0
  7. package/build-ts/{src/Commands.d.ts → Commands.d.ts} +171 -791
  8. package/build-ts/Commands.js +2708 -0
  9. package/build-ts/Errors.js +42 -0
  10. package/build-ts/{src/GlideClient.d.ts → GlideClient.d.ts} +55 -19
  11. package/build-ts/GlideClient.js +899 -0
  12. package/build-ts/{src/GlideClusterClient.d.ts → GlideClusterClient.d.ts} +78 -42
  13. package/build-ts/GlideClusterClient.js +1251 -0
  14. package/build-ts/Logger.js +67 -0
  15. package/build-ts/{src/ProtobufMessage.d.ts → ProtobufMessage.d.ts} +171 -634
  16. package/build-ts/ProtobufMessage.js +5265 -0
  17. package/build-ts/index.d.ts +16 -11
  18. package/build-ts/index.js +53 -216
  19. package/build-ts/native.d.ts +14 -0
  20. package/build-ts/native.js +342 -0
  21. package/build-ts/server-modules/GlideFt.js +628 -0
  22. package/build-ts/{src/server-modules → server-modules}/GlideFtOptions.d.ts +1 -1
  23. package/build-ts/server-modules/GlideFtOptions.js +5 -0
  24. package/build-ts/{src/server-modules → server-modules}/GlideJson.d.ts +65 -65
  25. package/build-ts/server-modules/GlideJson.js +1572 -0
  26. package/package.json +141 -64
  27. /package/build-ts/{src/Errors.d.ts → Errors.d.ts} +0 -0
  28. /package/build-ts/{src/Logger.d.ts → Logger.d.ts} +0 -0
  29. /package/build-ts/{src/server-modules → server-modules}/GlideFt.d.ts +0 -0
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
3
  */
4
- import { ClusterScanCursor, Script } from "glide-rs";
5
- import * as net from "net";
6
4
  import { AdvancedBaseClientConfiguration, BaseClient, BaseClientConfiguration, DecoderOption, GlideReturnType, GlideString, PubSubMsg } from "./BaseClient";
7
- import { ClusterScanOptions, FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsSingleResponse, InfoOptions, LolwutOptions } from "./Commands";
8
- import { command_request, connection_request } from "./ProtobufMessage";
9
- import { ClusterTransaction } from "./Transaction";
5
+ import { ClusterBatch } from "./Batch";
6
+ import { ClusterBatchOptions, ClusterScanOptions, FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsSingleResponse, InfoOptions, LolwutOptions } from "./Commands";
7
+ import { ClusterScanCursor, Script } from "./native";
10
8
  /** An extension to command option types with {@link Routes}. */
11
9
  export interface RouteOption {
12
10
  /**
@@ -385,25 +383,24 @@ export type SingleNodeRoute =
385
383
  | SlotKeyTypes | RouteByAddress;
386
384
  /**
387
385
  * Client used for connection to cluster servers.
386
+ * Use {@link createClient} to request a client.
388
387
  *
389
- * @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#cluster|Valkey Glide Wiki}.
388
+ * @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#cluster | Valkey Glide Wiki}.
390
389
  */
391
390
  export declare class GlideClusterClient extends BaseClient {
392
391
  /**
393
- * @internal
394
- */
395
- protected createClientRequest(options: GlideClusterClientConfiguration): connection_request.IConnectionRequest;
396
- /**
397
- * Creates a new `GlideClusterClient` instance and establishes connections to a Valkey GLIDE Cluster.
392
+ * Creates a new `GlideClusterClient` instance and establishes connections to a Valkey Cluster.
398
393
  *
399
394
  * @param options - The configuration options for the client, including cluster addresses, authentication credentials, TLS settings, periodic checks, and Pub/Sub subscriptions.
400
395
  * @returns A promise that resolves to a connected `GlideClusterClient` instance.
401
396
  *
402
397
  * @remarks
403
- * Use this static method to create and connect a `GlideClusterClient` to a Valkey GLIDE Cluster. The client will automatically handle connection establishment, including cluster topology discovery and handling of authentication and TLS configurations.
398
+ * Use this static method to create and connect a `GlideClusterClient` to a Valkey Cluster.
399
+ * The client will automatically handle connection establishment, including cluster topology discovery and handling of authentication and TLS configurations.
404
400
  *
405
- * ### Example - Connecting to a Cluster
401
+ * @example
406
402
  * ```typescript
403
+ * // Connecting to a Cluster
407
404
  * import { GlideClusterClient, GlideClusterClientConfiguration } from '@valkey/valkey-glide';
408
405
  *
409
406
  * const client = await GlideClusterClient.createClient({
@@ -439,18 +436,6 @@ export declare class GlideClusterClient extends BaseClient {
439
436
  * - **Pub/Sub Subscriptions**: Any channels or patterns specified in `pubsubSubscriptions` will be subscribed to upon connection.
440
437
  */
441
438
  static createClient(options: GlideClusterClientConfiguration): Promise<GlideClusterClient>;
442
- /**
443
- * @internal
444
- */
445
- static __createClient(options: BaseClientConfiguration, connectedSocket: net.Socket): Promise<GlideClusterClient>;
446
- /**
447
- * @internal
448
- */
449
- protected scanOptionsToProto(cursor: string, options?: ClusterScanOptions): command_request.ClusterScan;
450
- /**
451
- * @internal
452
- */
453
- protected createClusterScanPromise(cursor: ClusterScanCursor, options?: ClusterScanOptions & DecoderOption): Promise<[ClusterScanCursor, GlideString[]]>;
454
439
  /**
455
440
  * Incrementally iterates over the keys in the Cluster.
456
441
  *
@@ -533,25 +518,67 @@ export declare class GlideClusterClient extends BaseClient {
533
518
  */
534
519
  customCommand(args: GlideString[], options?: RouteOption & DecoderOption): Promise<ClusterResponse<GlideReturnType>>;
535
520
  /**
536
- * Execute a transaction by processing the queued commands.
521
+ * Executes a batch by processing the queued commands.
522
+ *
523
+ * **Routing Behavior:**
524
+ *
525
+ * - If a `route` is specified in {@link ClusterBatchOptions}, the entire batch is sent to the specified node.
526
+ * - If no `route` is specified:
527
+ * - **Atomic batches (Transactions):** Routed to the slot owner of the first key in the batch. If no key is found, the request is sent to a random node.
528
+ * - **Non-atomic batches (Pipelines):** Each command is routed to the node owning the corresponding key's slot. If no key is present, routing follows the command's request policy. Multi-node commands are automatically split and dispatched to the appropriate nodes.
529
+ *
530
+ * **Behavior Notes:**
531
+ *
532
+ * - **Atomic Batches (Transactions):** All key-based commands must map to the same hash slot. If keys span different slots, the transaction will fail. If the transaction fails due to a `WATCH` command, `exec` will return `null`.
537
533
  *
538
534
  * @see {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#transaction|Valkey Glide Wiki} for details on Valkey Transactions.
539
535
  *
540
- * @param transaction - A {@link ClusterTransaction} object containing a list of commands to be executed.
541
- *
542
- * @param options - (Optional) Additional parameters:
543
- * - (Optional) `route`: If `route` is not provided, the transaction will be routed to the slot owner of the first key found in the transaction.
544
- * If no key is found, the command will be sent to a random node.
545
- * If `route` is provided, the client will route the command to the nodes defined by `route`.
546
- * - (Optional) `decoder`: See {@link DecoderOption}.
547
- * @returns A list of results corresponding to the execution of each command in the transaction.
548
- * If a command returns a value, it will be included in the list. If a command doesn't return a value,
549
- * the list entry will be `null`.
550
- * If the transaction failed due to a `WATCH` command, `exec` will return `null`.
536
+ * **Retry and Redirection:**
537
+ *
538
+ * - If a redirection error occurs:
539
+ * - **Atomic batches (Transactions):** The entire transaction will be redirected.
540
+ * - **Non-atomic batches (Pipelines):** Only commands that encountered redirection errors will be retried.
541
+ * - Retries for failures will be handled according to the configured {@link BatchRetryStrategy}.
542
+ *
543
+ * @param batch - A {@link ClusterBatch} containing the commands to execute.
544
+ * @param raiseOnError - Determines how errors are handled within the batch response.
545
+ * - If `true`, the first encountered error in the batch will be raised as an exception of type {@link RequestError}
546
+ * after all retries and reconnections have been exhausted.
547
+ * - If `false`, errors will be included as part of the batch response, allowing the caller to process both successful and failed commands together.
548
+ * In this case, error details will be provided as instances of {@link RequestError} in the response list.
549
+ * @param options - (Optional) {@link ClusterBatchOptions} and {@link DecoderOption} specifying execution and decoding behavior.
550
+ * @returns A Promise resolving to an array of results, where each entry corresponds to a command’s execution result.
551
+ * - If the transaction fails due to a `WATCH` command, the promise resolves to `null`.
552
+ *
553
+ * @see {@link https://valkey.io/docs/topics/transactions/|Valkey Transactions (Atomic Batches)}
554
+ * @see {@link https://valkey.io/docs/topics/pipelining/|Valkey Pipelines (Non-Atomic Batches)}
555
+ * @example
556
+ * ```typescript
557
+ * // Atomic batch (transaction): all keys must share the same hash slot
558
+ * const atomicBatch = new ClusterBatch(true)
559
+ * .set('key', '1')
560
+ * .incr('key')
561
+ * .get('key');
562
+ *
563
+ * const atomicOptions = {timeout: 1000};
564
+ * const atomicResult = await clusterClient.exec(atomicBatch, false, atomicOptions);
565
+ * console.log('Atomic Batch Result:', atomicResult);
566
+ * // Output: ['OK', 2, '2']
567
+ *
568
+ * // Non-atomic batch (pipeline): keys may span different hash slots
569
+ * const nonAtomicBatch = new ClusterBatch(false)
570
+ * .set('key1', 'value1')
571
+ * .set('key2', 'value2')
572
+ * .get('key1')
573
+ * .get('key2');
574
+ *
575
+ * const pipelineOptions = { retryStrategy: { retryServerError: true, retryConnectionError: false } };
576
+ * const nonAtomicResult = await clusterClient.exec(nonAtomicBatch, false, pipelineOptions);
577
+ * console.log(nonAtomicResult);
578
+ * // Output: ['OK', 'OK', 'value1', 'value2']
579
+ * ```
551
580
  */
552
- exec(transaction: ClusterTransaction, options?: {
553
- route?: SingleNodeRoute;
554
- } & DecoderOption): Promise<GlideReturnType[] | null>;
581
+ exec(batch: ClusterBatch, raiseOnError: boolean, options?: ClusterBatchOptions & DecoderOption): Promise<GlideReturnType[] | null>;
555
582
  /**
556
583
  * Pings the server.
557
584
  *
@@ -589,6 +616,8 @@ export declare class GlideClusterClient extends BaseClient {
589
616
  *
590
617
  * The command will be routed to all primary nodes, unless `route` is provided.
591
618
  *
619
+ * Starting from server version 7, command supports multiple section arguments.
620
+ *
592
621
  * @see {@link https://valkey.io/commands/info/|valkey.io} for details.
593
622
  *
594
623
  * @param options - (Optional) Additional parameters:
@@ -596,8 +625,15 @@ export declare class GlideClusterClient extends BaseClient {
596
625
  * When no parameter is provided, {@link InfoOptions.Default|Default} is assumed.
597
626
  * - (Optional) `route`: see {@link RouteOption}.
598
627
  * @returns A string containing the information for the sections requested.
599
- * When specifying a route other than a single node,
628
+ * When specifying a route other than a single node,
600
629
  * it returns a dictionary where each address is the key and its corresponding node response is the value.
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * // Example usage of the info method with retrieving total_net_input_bytes from the result
634
+ * const result = await client.info(new Section[] { Section.STATS });
635
+ * console.log(someClusterParsingFunction(result, "total_net_input_bytes")); // Output: 1
636
+ * ```
601
637
  */
602
638
  info(options?: {
603
639
  sections?: InfoOptions[];
@@ -969,7 +1005,7 @@ export declare class GlideClusterClient extends BaseClient {
969
1005
  * Returns information about the function that's currently running and information about the
970
1006
  * available execution engines.
971
1007
  *
972
- * The command will be routed to all primary nodes, unless `route` is provided.
1008
+ * The command will be routed to all nodes, unless `route` is provided.
973
1009
  *
974
1010
  * @see {@link https://valkey.io/commands/function-stats/|valkey.io} for details.
975
1011
  * @remarks Since Valkey version 7.0.0.