@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
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConfigurationError = exports.ConnectionError = exports.ExecAbortError = exports.TIMEOUT_ERROR = exports.TimeoutError = exports.RequestError = exports.ClosingError = exports.ValkeyError = void 0;
7
+ /// Base class for errors.
8
+ class ValkeyError extends Error {
9
+ constructor(message) {
10
+ super();
11
+ this.message = message ?? "No error message provided";
12
+ }
13
+ get name() {
14
+ return this.constructor.name;
15
+ }
16
+ }
17
+ exports.ValkeyError = ValkeyError;
18
+ /// Errors that report that the client has closed and is no longer usable.
19
+ class ClosingError extends ValkeyError {
20
+ }
21
+ exports.ClosingError = ClosingError;
22
+ /// Errors that were reported during a request.
23
+ class RequestError extends ValkeyError {
24
+ }
25
+ exports.RequestError = RequestError;
26
+ /// Errors that are thrown when a request times out.
27
+ class TimeoutError extends RequestError {
28
+ }
29
+ exports.TimeoutError = TimeoutError;
30
+ exports.TIMEOUT_ERROR = new TimeoutError("Operation timed out");
31
+ /// Errors that are thrown when a transaction is aborted.
32
+ class ExecAbortError extends RequestError {
33
+ }
34
+ exports.ExecAbortError = ExecAbortError;
35
+ /// Errors that are thrown when a connection disconnects. These errors can be temporary, as the client will attempt to reconnect.
36
+ class ConnectionError extends RequestError {
37
+ }
38
+ exports.ConnectionError = ConnectionError;
39
+ /// Errors that are thrown when a request cannot be completed in current configuration settings.
40
+ class ConfigurationError extends RequestError {
41
+ }
42
+ exports.ConfigurationError = ConfigurationError;
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
3
3
  */
4
- import * as net from "net";
5
4
  import { AdvancedBaseClientConfiguration, BaseClient, BaseClientConfiguration, DecoderOption, GlideReturnType, GlideString, PubSubMsg } from "./BaseClient";
6
- import { FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsFullResponse, InfoOptions, LolwutOptions, ScanOptions } from "./Commands";
7
- import { connection_request } from "./ProtobufMessage";
8
- import { Transaction } from "./Transaction";
5
+ import { Batch } from "./Batch";
6
+ import { BatchOptions, FlushMode, FunctionListOptions, FunctionListResponse, FunctionRestorePolicy, FunctionStatsFullResponse, InfoOptions, LolwutOptions, ScanOptions } from "./Commands";
9
7
  export declare namespace GlideClientConfiguration {
10
8
  /**
11
9
  * Enum representing pubsub subscription modes.
@@ -127,22 +125,20 @@ export type GlideClientConfiguration = BaseClientConfiguration & {
127
125
  export type AdvancedGlideClientConfiguration = AdvancedBaseClientConfiguration & {};
128
126
  /**
129
127
  * Client used for connection to standalone servers.
128
+ * Use {@link createClient} to request a client.
130
129
  *
131
- * @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#standalone|Valkey Glide Wiki}.
130
+ * @see For full documentation refer to {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#standalone | Valkey Glide Wiki}.
132
131
  */
133
132
  export declare class GlideClient extends BaseClient {
134
133
  /**
135
- * @internal
136
- */
137
- protected createClientRequest(options: GlideClientConfiguration): connection_request.IConnectionRequest;
138
- /**
139
- * Creates a new `GlideClient` instance and establishes a connection to a standalone Valkey Glide server.
134
+ * Creates a new `GlideClient` instance and establishes a connection to a standalone Valkey server.
140
135
  *
141
136
  * @param options - The configuration options for the client, including server addresses, authentication credentials, TLS settings, database selection, reconnection strategy, and Pub/Sub subscriptions.
142
137
  * @returns A promise that resolves to a connected `GlideClient` instance.
143
138
  *
144
139
  * @remarks
145
- * Use this static method to create and connect a `GlideClient` to a standalone Valkey Glide server. The client will automatically handle connection establishment, including any authentication and TLS configurations.
140
+ * Use this static method to create and connect a `GlideClient` to a standalone Valkey server.
141
+ * The client will automatically handle connection establishment, including any authentication and TLS configurations.
146
142
  *
147
143
  * @example
148
144
  * ```typescript
@@ -184,22 +180,53 @@ export declare class GlideClient extends BaseClient {
184
180
  */
185
181
  static createClient(options: GlideClientConfiguration): Promise<GlideClient>;
186
182
  /**
187
- * @internal
188
- */
189
- static __createClient(options: BaseClientConfiguration, connectedSocket: net.Socket): Promise<GlideClient>;
190
- /**
191
- * Execute a transaction by processing the queued commands.
183
+ * Execute a batch by processing the queued commands.
184
+ *
185
+ * **Notes:**
186
+ * - **Atomic Batches - Transactions:** If the transaction fails due to a `WATCH` command, `EXEC` will return `null`.
192
187
  *
193
188
  * @see {@link https://github.com/valkey-io/valkey-glide/wiki/NodeJS-wrapper#transaction|Valkey Glide Wiki} for details on Valkey Transactions.
194
189
  *
195
- * @param transaction - A {@link Transaction} object containing a list of commands to be executed.
196
- * @param options - (Optional) See {@link DecoderOption}.
190
+ * @param batch - A {@link Batch} object containing a list of commands to be executed.
191
+ * @param raiseOnError - Determines how errors are handled within the batch response.
192
+ * - If `true`, the first the first encountered error in the batch will be raised as an exception of type {@link RequestError}
193
+ * after all retries and reconnections have been exhausted.
194
+ * - If `false`, errors will be included as part of the batch response, allowing the caller to process both successful and failed commands together.
195
+ * In this case, error details will be provided as instances of {@link RequestError} in the response list.
196
+ * @param options - (Optional) See {@link BatchOptions} and {@link DecoderOption}.
197
197
  * @returns A list of results corresponding to the execution of each command in the transaction.
198
198
  * If a command returns a value, it will be included in the list. If a command doesn't return a value,
199
199
  * the list entry will be `null`.
200
200
  * If the transaction failed due to a `WATCH` command, `exec` will return `null`.
201
+ *
202
+ * @see {@link https://valkey.io/docs/topics/transactions/|Valkey Transactions (Atomic Batches)} for details.
203
+ * @see {@link https://valkey.io/docs/topics/pipelining/|Valkey Pipelines (Non-Atomic Batches)} for details.
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * // Example 1: Atomic Batch (Transaction) with Options
208
+ * const transaction = new Batch(true) // Atomic (Transactional)
209
+ * .set("key", "value")
210
+ * .get("key");
211
+ *
212
+ * const result = await client.exec(transaction, false, {timeout: 1000}); // Execute the transaction with raiseOnError = false and a timeout of 1000ms
213
+ * console.log(result); // Output: ['OK', 'value']
214
+ * ```
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * // Example 2: Non-Atomic Batch (Pipelining) with Options
219
+ * const pipeline = new Batch(false) // Non-Atomic (Pipelining)
220
+ * .set("key1", "value1")
221
+ * .set("key2", "value2")
222
+ * .get("key1")
223
+ * .get("key2");
224
+ *
225
+ * const result = await client.exec(pipeline, false, {timeout: 1000}); // Execute the pipeline with raiseOnError = false and a timeout of 1000ms
226
+ * console.log(result); // Output: ['OK', 'OK', 'value1', 'value2']
227
+ * ```
201
228
  */
202
- exec(transaction: Transaction, options?: DecoderOption): Promise<GlideReturnType[] | null>;
229
+ exec(batch: Batch, raiseOnError: boolean, options?: BatchOptions & DecoderOption): Promise<GlideReturnType[] | null>;
203
230
  /** Executes a single command, without checking inputs. Every part of the command, including subcommands,
204
231
  * should be added as a separate value in args.
205
232
  *
@@ -251,11 +278,20 @@ export declare class GlideClient extends BaseClient {
251
278
  /**
252
279
  * Gets information and statistics about the server.
253
280
  *
281
+ * Starting from server version 7, command supports multiple section arguments.
282
+ *
254
283
  * @see {@link https://valkey.io/commands/info/|valkey.io} for details.
255
284
  *
256
285
  * @param sections - (Optional) A list of {@link InfoOptions} values specifying which sections of information to retrieve.
257
286
  * When no parameter is provided, {@link InfoOptions.Default|Default} is assumed.
258
287
  * @returns A string containing the information for the sections requested.
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * // Example usage of the info method with retrieving total_net_input_bytes from the result
292
+ * const result = await client.info(new Section[] { Section.STATS });
293
+ * console.log(someParsingFunction(result, "total_net_input_bytes")); // Output: 1
294
+ * ```
259
295
  */
260
296
  info(sections?: InfoOptions[]): Promise<string>;
261
297
  /**