@valkey/valkey-glide 1.3.4 → 1.3.5-rc0

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 (41) 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 +6050 -0
  5. package/build-ts/BaseClient.js.map +1 -0
  6. package/build-ts/{src/Transaction.d.ts → Batch.d.ts} +124 -67
  7. package/build-ts/Batch.js +3458 -0
  8. package/build-ts/Batch.js.map +1 -0
  9. package/build-ts/{src/Commands.d.ts → Commands.d.ts} +171 -791
  10. package/build-ts/Commands.js +2709 -0
  11. package/build-ts/Commands.js.map +1 -0
  12. package/build-ts/Errors.js +43 -0
  13. package/build-ts/Errors.js.map +1 -0
  14. package/build-ts/{src/GlideClient.d.ts → GlideClient.d.ts} +55 -19
  15. package/build-ts/GlideClient.js +900 -0
  16. package/build-ts/GlideClient.js.map +1 -0
  17. package/build-ts/{src/GlideClusterClient.d.ts → GlideClusterClient.d.ts} +78 -42
  18. package/build-ts/GlideClusterClient.js +1252 -0
  19. package/build-ts/GlideClusterClient.js.map +1 -0
  20. package/build-ts/Logger.js +68 -0
  21. package/build-ts/Logger.js.map +1 -0
  22. package/build-ts/{src/ProtobufMessage.d.ts → ProtobufMessage.d.ts} +135 -634
  23. package/build-ts/ProtobufMessage.js +5205 -0
  24. package/build-ts/index.d.ts +16 -11
  25. package/build-ts/index.js +54 -216
  26. package/build-ts/index.js.map +1 -0
  27. package/build-ts/native.d.ts +14 -0
  28. package/build-ts/native.js +343 -0
  29. package/build-ts/native.js.map +1 -0
  30. package/build-ts/server-modules/GlideFt.js +629 -0
  31. package/build-ts/server-modules/GlideFt.js.map +1 -0
  32. package/build-ts/{src/server-modules → server-modules}/GlideFtOptions.d.ts +1 -1
  33. package/build-ts/server-modules/GlideFtOptions.js +6 -0
  34. package/build-ts/server-modules/GlideFtOptions.js.map +1 -0
  35. package/build-ts/{src/server-modules → server-modules}/GlideJson.d.ts +65 -65
  36. package/build-ts/server-modules/GlideJson.js +1573 -0
  37. package/build-ts/server-modules/GlideJson.js.map +1 -0
  38. package/package.json +154 -63
  39. /package/build-ts/{src/Errors.d.ts → Errors.d.ts} +0 -0
  40. /package/build-ts/{src/Logger.d.ts → Logger.d.ts} +0 -0
  41. /package/build-ts/{src/server-modules → server-modules}/GlideFt.d.ts +0 -0
@@ -0,0 +1,1573 @@
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.JsonBatch = exports.GlideJson = void 0;
7
+ const GlideClient_1 = require("../GlideClient");
8
+ /**
9
+ * @internal
10
+ */
11
+ function _jsonGetOptionsToArgs(options) {
12
+ const result = [];
13
+ if (options.path) {
14
+ if (Array.isArray(options.path)) {
15
+ result.push(...options.path);
16
+ }
17
+ else {
18
+ result.push(options.path);
19
+ }
20
+ }
21
+ if (options.indent) {
22
+ result.push("INDENT", options.indent);
23
+ }
24
+ if (options.newline) {
25
+ result.push("NEWLINE", options.newline);
26
+ }
27
+ if (options.space) {
28
+ result.push("SPACE", options.space);
29
+ }
30
+ if (options.noescape) {
31
+ result.push("NOESCAPE");
32
+ }
33
+ return result;
34
+ }
35
+ /**
36
+ * @internal
37
+ */
38
+ function _executeCommand(client, args, options) {
39
+ if (client instanceof GlideClient_1.GlideClient) {
40
+ return client.customCommand(args, options);
41
+ }
42
+ else {
43
+ return client.customCommand(args, options);
44
+ }
45
+ }
46
+ /** Module for JSON commands. */
47
+ class GlideJson {
48
+ /**
49
+ * Sets the JSON value at the specified `path` stored at `key`.
50
+ *
51
+ * @param client The client to execute the command.
52
+ * @param key - The key of the JSON document.
53
+ * @param path - Represents the path within the JSON document where the value will be set.
54
+ * The key will be modified only if `value` is added as the last child in the specified `path`, or if the specified `path` acts as the parent of a new child being added.
55
+ * @param value - The value to set at the specific path, in JSON formatted bytes or str.
56
+ * @param options - (Optional) Additional parameters:
57
+ * - (Optional) `conditionalChange` - Set the value only if the given condition is met (within the key or path).
58
+ * Equivalent to [`XX` | `NX`] in the module API.
59
+ * - (Optional) `decoder`: see {@link DecoderOption}.
60
+ *
61
+ * @returns If the value is successfully set, returns `"OK"`.
62
+ * If `value` isn't set because of `conditionalChange`, returns `null`.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const value = {a: 1.0, b:2};
67
+ * const jsonStr = JSON.stringify(value);
68
+ * const result = await GlideJson.set(client, "doc", "$", jsonStr);
69
+ * console.log(result); // 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
70
+ *
71
+ * const jsonGetStr = await GlideJson.get(client, "doc", {path: "$"}); // Returns the value at path '$' in the JSON document stored at `doc` as JSON string.
72
+ * console.log(jsonGetStr); // '[{"a":1.0,"b":2}]'
73
+ * console.log(JSON.stringify(jsonGetStr)); // [{"a": 1.0, "b": 2}] # JSON object retrieved from the key `doc`
74
+ * ```
75
+ */
76
+ static async set(client, key, path, value, options) {
77
+ const args = ["JSON.SET", key, path, value];
78
+ if (options?.conditionalChange !== undefined) {
79
+ args.push(options.conditionalChange);
80
+ }
81
+ return _executeCommand(client, args, options);
82
+ }
83
+ /**
84
+ * Retrieves the JSON value at the specified `paths` stored at `key`.
85
+ *
86
+ * @param client The client to execute the command.
87
+ * @param key - The key of the JSON document.
88
+ * @param options - (Optional) Additional parameters:
89
+ * - (Optional) Options for formatting the byte representation of the JSON data. See {@link JsonGetOptions}.
90
+ * - (Optional) `decoder`: see {@link DecoderOption}.
91
+ * @returns
92
+ * - If one path is given:
93
+ * - For JSONPath (path starts with `$`):
94
+ * - Returns a stringified JSON list of bytes replies for every possible path,
95
+ * or a byte string representation of an empty array, if path doesn't exist.
96
+ * If `key` doesn't exist, returns `null`.
97
+ * - For legacy path (path doesn't start with `$`):
98
+ * Returns a byte string representation of the value in `path`.
99
+ * If `path` doesn't exist, an error is raised.
100
+ * If `key` doesn't exist, returns `null`.
101
+ * - If multiple paths are given:
102
+ * Returns a stringified JSON object in bytes, in which each path is a key, and it's corresponding value, is the value as if the path was executed in the command as a single path.
103
+ * In case of multiple paths, and `paths` are a mix of both JSONPath and legacy path, the command behaves as if all are JSONPath paths.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const jsonStr = await GlideJson.get(client, 'doc', {path: '$'});
108
+ * console.log(JSON.parse(jsonStr as string));
109
+ * // Output: [{"a": 1.0, "b" :2}] - JSON object retrieved from the key `doc`.
110
+ *
111
+ * const jsonData = await GlideJson.get(client, 'doc', {path: '$'});
112
+ * console.log(jsonData);
113
+ * // Output: '[{"a":1.0,"b":2}]' - Returns the value at path '$' in the JSON document stored at `doc`.
114
+ *
115
+ * const formattedJson = await GlideJson.get(client, 'doc', {
116
+ * ['$.a', '$.b']
117
+ * indent: " ",
118
+ * newline: "\n",
119
+ * space: " "
120
+ * });
121
+ * console.log(formattedJson);
122
+ * // Output: "{\n \"$.a\": [\n 1.0\n ],\n \"$.b\": [\n 2\n ]\n}" - Returns values at paths '$.a' and '$.b' with custom format.
123
+ *
124
+ * const nonExistingPath = await GlideJson.get(client, 'doc', {path: '$.non_existing_path'});
125
+ * console.log(nonExistingPath);
126
+ * // Output: "[]" - Empty array since the path does not exist in the JSON document.
127
+ * ```
128
+ */
129
+ static async get(client, key, options) {
130
+ const args = ["JSON.GET", key];
131
+ if (options) {
132
+ const optionArgs = _jsonGetOptionsToArgs(options);
133
+ args.push(...optionArgs);
134
+ }
135
+ return _executeCommand(client, args, options);
136
+ }
137
+ /**
138
+ * Retrieves the JSON values at the specified `path` stored at multiple `keys`.
139
+ *
140
+ * @remarks When in cluster mode, if keys in `keyValueMap` map to different hash slots, the command
141
+ * will be split across these slots and executed separately for each. This means the command
142
+ * is atomic only at the slot level. If one or more slot-specific requests fail, the entire
143
+ * call will return the first encountered error, even though some requests may have succeeded
144
+ * while others did not. If this behavior impacts your application logic, consider splitting
145
+ * the request into sub-requests per slot to ensure atomicity.
146
+ *
147
+ * @param client - The client to execute the command.
148
+ * @param keys - The keys of the JSON documents.
149
+ * @param path - The path within the JSON documents.
150
+ * @param options - (Optional) See {@link DecoderOption}.
151
+ * @returns
152
+ * - For JSONPath (path starts with `$`):
153
+ * Returns a stringified JSON list replies for every possible path, or a string representation
154
+ * of an empty array, if path doesn't exist.
155
+ * - For legacy path (path doesn't start with `$`):
156
+ * Returns a string representation of the value in `path`. If `path` doesn't exist,
157
+ * the corresponding array element will be `null`.
158
+ * - If a `key` doesn't exist, the corresponding array element will be `null`.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * await GlideJson.set(client, "doc1", "$", '{"a": 1, "b": ["one", "two"]}');
163
+ * await GlideJson.set(client, "doc2", "$", '{"a": 1, "c": false}');
164
+ * const res = await GlideJson.mget(client, [ "doc1", "doc2", "doc3" ], "$.c");
165
+ * console.log(res); // Output: ["[]", "[false]", null]
166
+ * ```
167
+ */
168
+ static async mget(client, keys, path, options) {
169
+ const args = ["JSON.MGET", ...keys, path];
170
+ return _executeCommand(client, args, options);
171
+ }
172
+ /**
173
+ * Inserts one or more values into the array at the specified `path` within the JSON
174
+ * document stored at `key`, before the given `index`.
175
+ *
176
+ * @param client - The client to execute the command.
177
+ * @param key - The key of the JSON document.
178
+ * @param path - The path within the JSON document.
179
+ * @param index - The array index before which values are inserted.
180
+ * @param values - The JSON values to be inserted into the array.
181
+ * JSON string values must be wrapped with quotes. For example, to insert `"foo"`, pass `"\"foo\""`.
182
+ * @returns
183
+ * - For JSONPath (path starts with `$`):
184
+ * Returns an array with a list of integers for every possible path,
185
+ * indicating the new length of the array, or `null` for JSON values matching
186
+ * the path that are not an array. If `path` does not exist, an empty array
187
+ * will be returned.
188
+ * - For legacy path (path doesn't start with `$`):
189
+ * Returns an integer representing the new length of the array. If multiple paths are
190
+ * matched, returns the length of the first modified array. If `path` doesn't
191
+ * exist or the value at `path` is not an array, an error is raised.
192
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * await GlideJson.set(client, "doc", "$", '[[], ["a"], ["a", "b"]]');
197
+ * const result = await GlideJson.arrinsert(client, "doc", "$[*]", 0, ['"c"', '{"key": "value"}', "true", "null", '["bar"]']);
198
+ * console.log(result); // Output: [5, 6, 7]
199
+ * const doc = await GlideJson.get(client, "doc");
200
+ * console.log(doc); // Output: '[["c",{"key":"value"},true,null,["bar"]],["c",{"key":"value"},true,null,["bar"],"a"],["c",{"key":"value"},true,null,["bar"],"a","b"]]'
201
+ * ```
202
+ * @example
203
+ * ```typescript
204
+ * await GlideJson.set(client, "doc", "$", '[[], ["a"], ["a", "b"]]');
205
+ * const result = await GlideJson.arrinsert(client, "doc", ".", 0, ['"c"'])
206
+ * console.log(result); // Output: 4
207
+ * const doc = await GlideJson.get(client, "doc");
208
+ * console.log(doc); // Output: '[\"c\",[],[\"a\"],[\"a\",\"b\"]]'
209
+ * ```
210
+ */
211
+ static async arrinsert(client, key, path, index, values) {
212
+ const args = ["JSON.ARRINSERT", key, path, index.toString(), ...values];
213
+ return _executeCommand(client, args);
214
+ }
215
+ /**
216
+ * Pops an element from the array located at `path` in the JSON document stored at `key`.
217
+ *
218
+ * @param client - The client to execute the command.
219
+ * @param key - The key of the JSON document.
220
+ * @param options - (Optional) See {@link JsonArrPopOptions} and {@link DecoderOption}.
221
+ * @returns
222
+ * - For JSONPath (path starts with `$`):
223
+ * Returns an array with a strings for every possible path, representing the popped JSON
224
+ * values, or `null` for JSON values matching the path that are not an array
225
+ * or an empty array.
226
+ * - For legacy path (path doesn't start with `$`):
227
+ * Returns a string representing the popped JSON value, or `null` if the
228
+ * array at `path` is empty. If multiple paths are matched, the value from
229
+ * the first matching array that is not empty is returned. If `path` doesn't
230
+ * exist or the value at `path` is not an array, an error is raised.
231
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * await GlideJson.set(client, "doc", "$", '{"a": [1, 2, true], "b": {"a": [3, 4, ["value", 3, false], 5], "c": {"a": 42}}}');
236
+ * let result = await GlideJson.arrpop(client, "doc", { path: "$.a", index: 1 });
237
+ * console.log(result); // Output: ['2'] - Popped second element from array at path `$.a`
238
+ * result = await GlideJson.arrpop(client, "doc", { path: "$..a" });
239
+ * console.log(result); // Output: ['true', '5', null] - Popped last elements from all arrays matching path `$..a`
240
+ *
241
+ * result = await GlideJson.arrpop(client, "doc", { path: "..a" });
242
+ * console.log(result); // Output: "1" - First match popped (from array at path ..a)
243
+ * // Even though only one value is returned from `..a`, subsequent arrays are also affected
244
+ * console.log(await GlideJson.get(client, "doc", "$..a")); // Output: "[[], [3, 4], 42]"
245
+ * ```
246
+ * @example
247
+ * ```typescript
248
+ * await GlideJson.set(client, "doc", "$", '[[], ["a"], ["a", "b", "c"]]');
249
+ * let result = await GlideJson.arrpop(client, "doc", { path: ".", index: -1 });
250
+ * console.log(result); // Output: '["a","b","c"]' - Popped last elements at path `.`
251
+ * ```
252
+ */
253
+ static async arrpop(client, key, options) {
254
+ const args = ["JSON.ARRPOP", key];
255
+ if (options?.path)
256
+ args.push(options?.path);
257
+ if (options && "index" in options && options.index)
258
+ args.push(options?.index.toString());
259
+ return _executeCommand(client, args, options);
260
+ }
261
+ /**
262
+ * Retrieves the length of the array at the specified `path` within the JSON document stored at `key`.
263
+ *
264
+ * @param client - The client to execute the command.
265
+ * @param key - The key of the JSON document.
266
+ * @param options - (Optional) Additional parameters:
267
+ * - (Optional) `path`: The path within the JSON document. Defaults to the root (`"."`) if not specified.
268
+ * @returns
269
+ * - For JSONPath (path starts with `$`):
270
+ * Returns an array with a list of integers for every possible path,
271
+ * indicating the length of the array, or `null` for JSON values matching
272
+ * the path that are not an array. If `path` does not exist, an empty array
273
+ * will be returned.
274
+ * - For legacy path (path doesn't start with `$`):
275
+ * Returns an integer representing the length of the array. If multiple paths are
276
+ * matched, returns the length of the first matching array. If `path` doesn't
277
+ * exist or the value at `path` is not an array, an error is raised.
278
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * await GlideJson.set(client, "doc", "$", '{"a": [1, 2, 3], "b": {"a": [1, 2], "c": {"a": 42}}}');
283
+ * console.log(await GlideJson.arrlen(client, "doc", { path: "$" })); // Output: [null] - No array at the root path.
284
+ * console.log(await GlideJson.arrlen(client, "doc", { path: "$.a" })); // Output: [3] - Retrieves the length of the array at path $.a.
285
+ * console.log(await GlideJson.arrlen(client, "doc", { path: "$..a" })); // Output: [3, 2, null] - Retrieves lengths of arrays found at all levels of the path `$..a`.
286
+ * console.log(await GlideJson.arrlen(client, "doc", { path: "..a" })); // Output: 3 - Legacy path retrieves the first array match at path `..a`.
287
+ * ```
288
+ * @example
289
+ * ```typescript
290
+ * await GlideJson.set(client, "doc", "$", '[1, 2, 3, 4]');
291
+ * console.log(await GlideJson.arrlen(client, "doc")); // Output: 4 - the length of array at root.
292
+ * ```
293
+ */
294
+ static async arrlen(client, key, options) {
295
+ const args = ["JSON.ARRLEN", key];
296
+ if (options?.path)
297
+ args.push(options?.path);
298
+ return _executeCommand(client, args);
299
+ }
300
+ /**
301
+ * Trims an array at the specified `path` within the JSON document stored at `key` so that it becomes a subarray [start, end], both inclusive.
302
+ * If `start` < 0, it is treated as 0.
303
+ * If `end` >= size (size of the array), it is treated as size-1.
304
+ * If `start` >= size or `start` > `end`, the array is emptied and 0 is returned.
305
+ *
306
+ * @param client - The client to execute the command.
307
+ * @param key - The key of the JSON document.
308
+ * @param path - The path within the JSON document.
309
+ * @param start - The start index, inclusive.
310
+ * @param end - The end index, inclusive.
311
+ * @returns
312
+ * - For JSONPath (`path` starts with `$`):
313
+ * - Returns a list of integer replies for every possible path, indicating the new length of the array,
314
+ * or `null` for JSON values matching the path that are not an array.
315
+ * - If the array is empty, its corresponding return value is 0.
316
+ * - If `path` doesn't exist, an empty array will be returned.
317
+ * - If an index argument is out of bounds, an error is raised.
318
+ * - For legacy path (`path` doesn't start with `$`):
319
+ * - Returns an integer representing the new length of the array.
320
+ * - If the array is empty, its corresponding return value is 0.
321
+ * - If multiple paths match, the length of the first trimmed array match is returned.
322
+ * - If `path` doesn't exist, or the value at `path` is not an array, an error is raised.
323
+ * - If an index argument is out of bounds, an error is raised.
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * console.log(await GlideJson.set(client, "doc", "$", '[[], ["a"], ["a", "b"], ["a", "b", "c"]]');
328
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
329
+ * const result = await GlideJson.arrtrim(client, "doc", "$[*]", 0, 1);
330
+ * console.log(result);
331
+ * // Output: [0, 1, 2, 2]
332
+ * console.log(await GlideJson.get(client, "doc", "$"));
333
+ * // Output: '[[],["a"],["a","b"],["a","b"]]' - Returns the value at path '$' in the JSON document stored at `doc`.
334
+ * ```
335
+ * @example
336
+ * ```typescript
337
+ * console.log(await GlideJson.set(client, "doc", "$", '{"children": ["John", "Jack", "Tom", "Bob", "Mike"]}');
338
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
339
+ * result = await GlideJson.arrtrim(client, "doc", ".children", 0, 1);
340
+ * console.log(result);
341
+ * // Output: 2
342
+ * console.log(await GlideJson.get(client, "doc", ".children"));
343
+ * // Output: '["John", "Jack"]' - Returns the value at path '$' in the JSON document stored at `doc`.
344
+ * ```
345
+ */
346
+ static async arrtrim(client, key, path, start, end) {
347
+ const args = [
348
+ "JSON.ARRTRIM",
349
+ key,
350
+ path,
351
+ start.toString(),
352
+ end.toString(),
353
+ ];
354
+ return _executeCommand(client, args);
355
+ }
356
+ /**
357
+ * Searches for the first occurrence of a `scalar` JSON value in the arrays at the `path`.
358
+ * Out of range errors are treated by rounding the index to the array's `start` and `end.
359
+ * If `start` > `end`, return `-1` (not found).
360
+ *
361
+ * @param client - The client to execute the command.
362
+ * @param key - The key of the JSON document.
363
+ * @param path - The path within the JSON document.
364
+ * @param scalar - The scalar value to search for.
365
+ * @param options - (Optional) Additional parameters:
366
+ * - (Optional) `start`: The start index, inclusive. Default to 0 if not provided.
367
+ * - (Optional) `end`: The end index, exclusive. Default to 0 if not provided.
368
+ * 0 or -1 means the last element is included.
369
+ * @returns
370
+ * - For JSONPath (path starts with `$`):
371
+ * Returns an array with a list of integers for every possible path,
372
+ * indicating the index of the matching element. The value is `-1` if not found.
373
+ * If a value is not an array, its corresponding return value is `null`.
374
+ * - For legacy path (path doesn't start with `$`):
375
+ * Returns an integer representing the index of matching element, or `-1` if
376
+ * not found. If the value at the `path` is not an array, an error is raised.
377
+ *
378
+ * @example
379
+ * ```typescript
380
+ * await GlideJson.set(client, "doc", "$", '{"a": ["value", 3], "b": {"a": [3, ["value", false], 5]}}');
381
+ * console.log(await GlideJson.arrindex(client, "doc", "$..a", 3, { start: 3, end: 3 }); // Output: [2, -1]
382
+ * ```
383
+ */
384
+ static async arrindex(client, key, path, scalar, options) {
385
+ const args = ["JSON.ARRINDEX", key, path];
386
+ if (typeof scalar === `number`) {
387
+ args.push(scalar.toString());
388
+ }
389
+ else if (typeof scalar === `boolean`) {
390
+ args.push(scalar ? `true` : `false`);
391
+ }
392
+ else if (scalar !== null) {
393
+ args.push(scalar);
394
+ }
395
+ else {
396
+ args.push(`null`);
397
+ }
398
+ if (options?.start !== undefined)
399
+ args.push(options?.start.toString());
400
+ if (options?.end !== undefined)
401
+ args.push(options?.end.toString());
402
+ return _executeCommand(client, args);
403
+ }
404
+ /**
405
+ * Toggles a Boolean value stored at the specified `path` within the JSON document stored at `key`.
406
+ *
407
+ * @param client - The client to execute the command.
408
+ * @param key - The key of the JSON document.
409
+ * @param options - (Optional) Additional parameters:
410
+ * - (Optional) `path`: The path within the JSON document. Defaults to the root (`"."`) if not specified.
411
+ * @returns - For JSONPath (`path` starts with `$`), returns a list of boolean replies for every possible path, with the toggled boolean value,
412
+ * or `null` for JSON values matching the path that are not boolean.
413
+ * - For legacy path (`path` doesn't starts with `$`), returns the value of the toggled boolean in `path`.
414
+ * - Note that when sending legacy path syntax, If `path` doesn't exist or the value at `path` isn't a boolean, an error is raised.
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * const value = {bool: true, nested: {bool: false, nested: {bool: 10}}};
419
+ * const jsonStr = JSON.stringify(value);
420
+ * const resultSet = await GlideJson.set(client, "doc", "$", jsonStr);
421
+ * // Output: 'OK'
422
+ *
423
+ * const resultToggle = await.GlideJson.toggle(client, "doc", {path: "$.bool"});
424
+ * // Output: [false, true, null] - Indicates successful toggling of the Boolean values at path '$.bool' in the key stored at `doc`.
425
+ *
426
+ * const resultToggle = await.GlideJson.toggle(client, "doc", {path: "bool"});
427
+ * // Output: true - Indicates successful toggling of the Boolean value at path 'bool' in the key stored at `doc`.
428
+ *
429
+ * const resultToggle = await.GlideJson.toggle(client, "doc", {path: "bool"});
430
+ * // Output: true - Indicates successful toggling of the Boolean value at path 'bool' in the key stored at `doc`.
431
+ *
432
+ * const jsonGetStr = await GlideJson.get(client, "doc", {path: "$"});
433
+ * console.log(JSON.stringify(jsonGetStr));
434
+ * // Output: [{bool: true, nested: {bool: true, nested: {bool: 10}}}] - The updated JSON value in the key stored at `doc`.
435
+ *
436
+ * // Without specifying a path, the path defaults to root.
437
+ * console.log(await GlideJson.set(client, "doc2", ".", true)); // Output: "OK"
438
+ * console.log(await GlideJson.toggle(client, {path: "doc2"})); // Output: "false"
439
+ * console.log(await GlideJson.toggle(client, {path: "doc2"})); // Output: "true"
440
+ * ```
441
+ */
442
+ static async toggle(client, key, options) {
443
+ const args = ["JSON.TOGGLE", key];
444
+ if (options) {
445
+ args.push(options.path);
446
+ }
447
+ return _executeCommand(client, args);
448
+ }
449
+ /**
450
+ * Deletes the JSON value at the specified `path` within the JSON document stored at `key`.
451
+ *
452
+ * @param client - The client to execute the command.
453
+ * @param key - The key of the JSON document.
454
+ * @param options - (Optional) Additional parameters:
455
+ * - (Optional) `path`: If `null`, deletes the entire JSON document at `key`.
456
+ * @returns - The number of elements removed. If `key` or `path` doesn't exist, returns 0.
457
+ *
458
+ * @example
459
+ * ```typescript
460
+ * console.log(await GlideJson.set(client, "doc", "$", '{a: 1, nested: {a:2, b:3}}'));
461
+ * // Output: "OK" - Indicates successful setting of the value at path '$' in the key stored at `doc`.
462
+ * console.log(await GlideJson.del(client, "doc", {path: "$..a"}));
463
+ * // Output: 2 - Indicates successful deletion of the specific values in the key stored at `doc`.
464
+ * console.log(await GlideJson.get(client, "doc", {path: "$"}));
465
+ * // Output: "[{nested: {b: 3}}]" - Returns the value at path '$' in the JSON document stored at `doc`.
466
+ * console.log(await GlideJson.del(client, "doc"));
467
+ * // Output: 1 - Deletes the entire JSON document stored at `doc`.
468
+ * ```
469
+ */
470
+ static async del(client, key, options) {
471
+ const args = ["JSON.DEL", key];
472
+ if (options) {
473
+ args.push(options.path);
474
+ }
475
+ return _executeCommand(client, args);
476
+ }
477
+ /**
478
+ * Deletes the JSON value at the specified `path` within the JSON document stored at `key`. This command is
479
+ * an alias of {@link del}.
480
+ *
481
+ * @param client - The client to execute the command.
482
+ * @param key - The key of the JSON document.
483
+ * @param options - (Optional) Additional parameters:
484
+ * - (Optional) `path`: If `null`, deletes the entire JSON document at `key`.
485
+ * @returns - The number of elements removed. If `key` or `path` doesn't exist, returns 0.
486
+ *
487
+ * @example
488
+ * ```typescript
489
+ * console.log(await GlideJson.set(client, "doc", "$", '{a: 1, nested: {a:2, b:3}}'));
490
+ * // Output: "OK" - Indicates successful setting of the value at path '$' in the key stored at `doc`.
491
+ * console.log(await GlideJson.forget(client, "doc", {path: "$..a"}));
492
+ * // Output: 2 - Indicates successful deletion of the specific values in the key stored at `doc`.
493
+ * console.log(await GlideJson.get(client, "doc", {path: "$"}));
494
+ * // Output: "[{nested: {b: 3}}]" - Returns the value at path '$' in the JSON document stored at `doc`.
495
+ * console.log(await GlideJson.forget(client, "doc"));
496
+ * // Output: 1 - Deletes the entire JSON document stored at `doc`.
497
+ * ```
498
+ */
499
+ static async forget(client, key, options) {
500
+ const args = ["JSON.FORGET", key];
501
+ if (options) {
502
+ args.push(options.path);
503
+ }
504
+ return _executeCommand(client, args);
505
+ }
506
+ /**
507
+ * Reports the type of values at the given path.
508
+ *
509
+ * @param client - The client to execute the command.
510
+ * @param key - The key of the JSON document.
511
+ * @param options - (Optional) Additional parameters:
512
+ * - (Optional) `path`: Defaults to root (`"."`) if not provided.
513
+ * @returns
514
+ * - For JSONPath (path starts with `$`):
515
+ * - Returns an array of strings that represents the type of value at each path.
516
+ * The type is one of "null", "boolean", "string", "number", "integer", "object" and "array".
517
+ * - If a path does not exist, its corresponding return value is `null`.
518
+ * - Empty array if the document key does not exist.
519
+ * - For legacy path (path doesn't start with `$`):
520
+ * - String that represents the type of the value.
521
+ * - `null` if the document key does not exist.
522
+ * - `null` if the JSON path is invalid or does not exist.
523
+ *
524
+ * @example
525
+ * ```typescript
526
+ * console.log(await GlideJson.set(client, "doc", "$", '[1, 2.3, "foo", true, null, {}, []]'));
527
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
528
+ * const result = await GlideJson.type(client, "doc", {path: "$[*]"});
529
+ * console.log(result);
530
+ * // Output: ["integer", "number", "string", "boolean", null, "object", "array"];
531
+ * console.log(await GlideJson.set(client, "doc2", ".", "{Name: 'John', Age: 27}"));
532
+ * console.log(await GlideJson.type(client, "doc2")); // Output: "object"
533
+ * console.log(await GlideJson.type(client, "doc2", {path: ".Age"})); // Output: "integer"
534
+ * ```
535
+ */
536
+ static async type(client, key, options) {
537
+ const args = ["JSON.TYPE", key];
538
+ if (options) {
539
+ args.push(options.path);
540
+ }
541
+ return _executeCommand(client, args);
542
+ }
543
+ /**
544
+ * Clears arrays or objects at the specified JSON path in the document stored at `key`.
545
+ * Numeric values are set to `0`, boolean values are set to `false`, and string values are converted to empty strings.
546
+ *
547
+ * @param client - The client to execute the command.
548
+ * @param key - The key of the JSON document.
549
+ * @param options - (Optional) Additional parameters:
550
+ * - (Optional) `path`: The JSON path to the arrays or objects to be cleared. Defaults to root if not provided.
551
+ * @returns The number of containers cleared, numeric values zeroed, and booleans toggled to `false`,
552
+ * and string values converted to empty strings.
553
+ * If `path` doesn't exist, or the value at `path` is already empty (e.g., an empty array, object, or string), `0` is returned.
554
+ * If `key doesn't exist, an error is raised.
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * console.log(await GlideJson.set(client, "doc", "$", '{"obj":{"a":1, "b":2}, "arr":[1,2,3], "str": "foo", "bool": true, "int": 42, "float": 3.14, "nullVal": null}'));
559
+ * // Output: 'OK' - JSON document is successfully set.
560
+ * console.log(await GlideJson.clear(client, "doc", {path: "$.*"}));
561
+ * // Output: 6 - 6 values are cleared (arrays/objects/strings/numbers/booleans), but `null` remains as is.
562
+ * console.log(await GlideJson.get(client, "doc", "$"));
563
+ * // Output: '[{"obj":{},"arr":[],"str":"","bool":false,"int":0,"float":0.0,"nullVal":null}]'
564
+ * console.log(await GlideJson.clear(client, "doc", {path: "$.*"}));
565
+ * // Output: 0 - No further clearing needed since the containers are already empty and the values are defaults.
566
+ *
567
+ * console.log(await GlideJson.set(client, "doc", "$", '{"a": 1, "b": {"a": [5, 6, 7], "b": {"a": true}}, "c": {"a": "value", "b": {"a": 3.5}}, "d": {"a": {"foo": "foo"}}, "nullVal": null}'));
568
+ * // Output: 'OK'
569
+ * console.log(await GlideJson.clear(client, "doc", {path: "b.a[1:3]"}));
570
+ * // Output: 2 - 2 elements (`6` and `7`) are cleared.
571
+ * console.log(await GlideJson.clear(client, "doc", {path: "b.a[1:3]"}));
572
+ * // Output: 0 - No elements cleared since specified slice has already been cleared.
573
+ * console.log(await GlideJson.get(client, "doc", {path: "$..a"}));
574
+ * // Output: '[1,[5,0,0],true,"value",3.5,{"foo":"foo"}]'
575
+ *
576
+ * console.log(await GlideJson.clear(client, "doc", {path: "$..a"}));
577
+ * // Output: 6 - All numeric, boolean, and string values across paths are cleared.
578
+ * console.log(await GlideJson.get(client, "doc", {path: "$..a"}));
579
+ * // Output: '[0,[],false,"",0.0,{}]'
580
+ * ```
581
+ */
582
+ static async clear(client, key, options) {
583
+ const args = ["JSON.CLEAR", key];
584
+ if (options) {
585
+ args.push(options.path);
586
+ }
587
+ return _executeCommand(client, args);
588
+ }
589
+ /**
590
+ * Retrieve the JSON value at the specified `path` within the JSON document stored at `key`.
591
+ * The returning result is in the Valkey or Redis OSS Serialization Protocol (RESP).
592
+ * - JSON null is mapped to the RESP Null Bulk String.
593
+ * - JSON Booleans are mapped to RESP Simple string.
594
+ * - JSON integers are mapped to RESP Integers.
595
+ * - JSON doubles are mapped to RESP Bulk Strings.
596
+ * - JSON strings are mapped to RESP Bulk Strings.
597
+ * - JSON arrays are represented as RESP arrays, where the first element is the simple string [, followed by the array's elements.
598
+ * - JSON objects are represented as RESP object, where the first element is the simple string {, followed by key-value pairs, each of which is a RESP bulk string.
599
+ *
600
+ * @param client - The client to execute the command.
601
+ * @param key - The key of the JSON document.
602
+ * @param options - (Optional) Additional parameters:
603
+ * - (Optional) `path`: The path within the JSON document, defaults to root (`"."`) if not provided.
604
+ * - (Optional) `decoder`: see {@link DecoderOption}.
605
+ * @returns
606
+ * - For JSONPath (path starts with `$`):
607
+ * - Returns an array of replies for every possible path, indicating the RESP form of the JSON value.
608
+ * If `path` doesn't exist, returns an empty array.
609
+ * - For legacy path (path doesn't start with `$`):
610
+ * - Returns a single reply for the JSON value at the specified `path`, in its RESP form.
611
+ * If multiple paths match, the value of the first JSON value match is returned. If `path` doesn't exist, an error is raised.
612
+ * - If `key` doesn't exist, `null` is returned.
613
+ *
614
+ * @example
615
+ * ```typescript
616
+ * console.log(await GlideJson.set(client, "doc", ".", '{a: [1, 2, 3], b: {a: [1, 2], c: {a: 42}}}'));
617
+ * // Output: 'OK' - Indicates successful setting of the value at path '.' in the key stored at `doc`.
618
+ * const result = await GlideJson.resp(client, "doc", {path: "$..a"});
619
+ * console.log(result);
620
+ * // Output: [ ["[", 1, 2, 3], ["[", 1, 2], [42]];
621
+ * console.log(await GlideJson.type(client, "doc", {path: "..a"})); // Output: ["[", 1, 2, 3]
622
+ * ```
623
+ */
624
+ static async resp(client, key, options) {
625
+ const args = ["JSON.RESP", key];
626
+ if (options) {
627
+ args.push(options.path);
628
+ }
629
+ return _executeCommand(client, args, options);
630
+ }
631
+ /**
632
+ * Returns the length of the JSON string value stored at the specified `path` within
633
+ * the JSON document stored at `key`.
634
+ *
635
+ * @param client - The client to execute the command.
636
+ * @param key - The key of the JSON document.
637
+ * @param options - (Optional) Additional parameters:
638
+ * - (Optional) `path`: The path within the JSON document, Defaults to root (`"."`) if not provided.
639
+ * @returns
640
+ * - For JSONPath (path starts with `$`):
641
+ * - Returns a list of integer replies for every possible path, indicating the length of
642
+ * the JSON string value, or `null` for JSON values matching the path that
643
+ * are not string.
644
+ * - For legacy path (path doesn't start with `$`):
645
+ * - Returns the length of the JSON value at `path` or `null` if `key` doesn't exist.
646
+ * - If multiple paths match, the length of the first matched string is returned.
647
+ * - If the JSON value at`path` is not a string or if `path` doesn't exist, an error is raised.
648
+ * - If `key` doesn't exist, `null` is returned.
649
+ *
650
+ * @example
651
+ * ```typescript
652
+ * console.log(await GlideJson.set(client, "doc", "$", '{a:"foo", nested: {a: "hello"}, nested2: {a: 31}}'));
653
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
654
+ * console.log(await GlideJson.strlen(client, "doc", {path: "$..a"}));
655
+ * // Output: [3, 5, null] - The length of the string values at path '$..a' in the key stored at `doc`.
656
+ *
657
+ * console.log(await GlideJson.strlen(client, "doc", {path: "nested.a"}));
658
+ * // Output: 5 - The length of the JSON value at path 'nested.a' in the key stored at `doc`.
659
+ *
660
+ * console.log(await GlideJson.strlen(client, "doc", {path: "$"}));
661
+ * // Output: [null] - Returns an array with null since the value at root path does in the JSON document stored at `doc` is not a string.
662
+ *
663
+ * console.log(await GlideJson.strlen(client, "non_existent_key", {path: "."}));
664
+ * // Output: null - return null if key does not exist.
665
+ * ```
666
+ */
667
+ static async strlen(client, key, options) {
668
+ const args = ["JSON.STRLEN", key];
669
+ if (options) {
670
+ args.push(options.path);
671
+ }
672
+ return _executeCommand(client, args);
673
+ }
674
+ /**
675
+ * Appends the specified `value` to the string stored at the specified `path` within the JSON document stored at `key`.
676
+ *
677
+ * @param client - The client to execute the command.
678
+ * @param key - The key of the JSON document.
679
+ * @param value - The value to append to the string. Must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
680
+ * @param options - (Optional) Additional parameters:
681
+ * - (Optional) `path`: The path within the JSON document, defaults to root (`"."`) if not provided.
682
+ * @returns
683
+ * - For JSONPath (path starts with `$`):
684
+ * - Returns a list of integer replies for every possible path, indicating the length of the resulting string after appending `value`,
685
+ * or None for JSON values matching the path that are not string.
686
+ * - If `key` doesn't exist, an error is raised.
687
+ * - For legacy path (path doesn't start with `$`):
688
+ * - Returns the length of the resulting string after appending `value` to the string at `path`.
689
+ * - If multiple paths match, the length of the last updated string is returned.
690
+ * - If the JSON value at `path` is not a string of if `path` doesn't exist, an error is raised.
691
+ * - If `key` doesn't exist, an error is raised.
692
+ *
693
+ * @example
694
+ * ```typescript
695
+ * console.log(await GlideJson.set(client, "doc", "$", '{a:"foo", nested: {a: "hello"}, nested2: {a: 31}}'));
696
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
697
+ * console.log(await GlideJson.strappend(client, "doc", jsonpy.dumps("baz"), {path: "$..a"}))
698
+ * // Output: [6, 8, null] - The new length of the string values at path '$..a' in the key stored at `doc` after the append operation.
699
+ *
700
+ * console.log(await GlideJson.strappend(client, "doc", '"foo"', {path: "nested.a"}));
701
+ * // Output: 11 - The length of the string value after appending "foo" to the string at path 'nested.array' in the key stored at `doc`.
702
+ *
703
+ * const result = JSON.parse(await GlideJson.get(client, "doc", {path: "$"}));
704
+ * console.log(result);
705
+ * // Output: [{"a":"foobaz", "nested": {"a": "hellobazfoo"}, "nested2": {"a": 31}}] - The updated JSON value in the key stored at `doc`.
706
+ * ```
707
+ */
708
+ static async strappend(client, key, value, options) {
709
+ const args = ["JSON.STRAPPEND", key];
710
+ if (options) {
711
+ args.push(options.path);
712
+ }
713
+ args.push(value);
714
+ return _executeCommand(client, args);
715
+ }
716
+ /**
717
+ * Appends one or more `values` to the JSON array at the specified `path` within the JSON
718
+ * document stored at `key`.
719
+ *
720
+ * @param client - The client to execute the command.
721
+ * @param key - The key of the JSON document.
722
+ * @param path - The path within the JSON document.
723
+ * @param values - The JSON values to be appended to the array.
724
+ * JSON string values must be wrapped with quotes. For example, to append `"foo"`, pass `"\"foo\""`.
725
+ * @returns
726
+ * - For JSONPath (path starts with `$`):
727
+ * Returns an array with a list of integers for every possible path,
728
+ * indicating the new length of the array, or `null` for JSON values matching
729
+ * the path that are not an array. If `path` does not exist, an empty array
730
+ * will be returned.
731
+ * - For legacy path (path doesn't start with `$`):
732
+ * Returns an integer representing the new length of the array. If multiple paths are
733
+ * matched, returns the length of the first modified array. If `path` doesn't
734
+ * exist or the value at `path` is not an array, an error is raised.
735
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
736
+ *
737
+ * @example
738
+ * ```typescript
739
+ * await GlideJson.set(client, "doc", "$", '{"a": 1, "b": ["one", "two"]}');
740
+ * const result = await GlideJson.arrappend(client, "doc", "$.b", ["three"]);
741
+ * console.log(result); // Output: [3] - the new length of the array at path '$.b' after appending the value.
742
+ * const result = await GlideJson.arrappend(client, "doc", ".b", ["four"]);
743
+ * console.log(result); // Output: 4 - the new length of the array at path '.b' after appending the value.
744
+ * const doc = await json.get(client, "doc");
745
+ * console.log(doc); // Output: '{"a": 1, "b": ["one", "two", "three", "four"]}'
746
+ * ```
747
+ */
748
+ static async arrappend(client, key, path, values) {
749
+ const args = ["JSON.ARRAPPEND", key, path, ...values];
750
+ return _executeCommand(client, args);
751
+ }
752
+ /**
753
+ * Reports memory usage in bytes of a JSON object at the specified `path` within the JSON document stored at `key`.
754
+ *
755
+ * @param client - The client to execute the command.
756
+ * @param key - The key of the JSON document.
757
+ * @param value - The value to append to the string. Must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
758
+ * @param options - (Optional) Additional parameters:
759
+ * - (Optional) `path`: The path within the JSON document, returns total memory usage if no path is given.
760
+ * @returns
761
+ * - For JSONPath (path starts with `$`):
762
+ * - Returns an array of numbers for every possible path, indicating the memory usage.
763
+ * If `path` does not exist, an empty array will be returned.
764
+ * - For legacy path (path doesn't start with `$`):
765
+ * - Returns an integer representing the memory usage. If multiple paths are matched,
766
+ * returns the data of the first matching object. If `path` doesn't exist, an error is raised.
767
+ * - If `key` doesn't exist, returns `null`.
768
+ *
769
+ * @example
770
+ * ```typescript
771
+ * console.log(await GlideJson.set(client, "doc", "$", '[1, 2.3, "foo", true, null, {}, [], {a:1, b:2}, [1, 2, 3]]'));
772
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
773
+ * console.log(await GlideJson.debugMemory(client, "doc", {path: ".."});
774
+ * // Output: 258
775
+ * ```
776
+ */
777
+ static async debugMemory(client, key, options) {
778
+ const args = ["JSON.DEBUG", "MEMORY", key];
779
+ if (options) {
780
+ args.push(options.path);
781
+ }
782
+ return _executeCommand(client, args);
783
+ }
784
+ /**
785
+ * Reports the number of fields at the specified `path` within the JSON document stored at `key`.
786
+ *
787
+ * @param client - The client to execute the command.
788
+ * @param key - The key of the JSON document.
789
+ * @param value - The value to append to the string. Must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
790
+ * @param options - (Optional) Additional parameters:
791
+ * - (Optional) `path`: The path within the JSON document, returns total number of fields if no path is given.
792
+ * @returns
793
+ * - For JSONPath (path starts with `$`):
794
+ * - Returns an array of numbers for every possible path, indicating the number of fields.
795
+ * If `path` does not exist, an empty array will be returned.
796
+ * - For legacy path (path doesn't start with `$`):
797
+ * - Returns an integer representing the memory usage. If multiple paths are matched,
798
+ * returns the data of the first matching object. If `path` doesn't exist, an error is raised.
799
+ * - If `key` doesn't exist, returns `null`.
800
+ *
801
+ * @example
802
+ * ```typescript
803
+ * console.log(await GlideJson.set(client, "doc", "$", '[1, 2.3, "foo", true, null, {}, [], {a:1, b:2}, [1, 2, 3]]'));
804
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
805
+ * console.log(await GlideJson.debugFields(client, "doc", {path: "$[*]"});
806
+ * // Output: [1, 1, 1, 1, 1, 0, 0, 2, 3]
807
+ * ```
808
+ */
809
+ static async debugFields(client, key, options) {
810
+ const args = ["JSON.DEBUG", "FIELDS", key];
811
+ if (options) {
812
+ args.push(options.path);
813
+ }
814
+ return _executeCommand(client, args);
815
+ }
816
+ /**
817
+ * Increments or decrements the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.
818
+ *
819
+ * @param client - The client to execute the command.
820
+ * @param key - The key of the JSON document.
821
+ * @param path - The path within the JSON document.
822
+ * @param num - The number to increment or decrement by.
823
+ * @returns
824
+ * - For JSONPath (path starts with `$`):
825
+ * - Returns a string representation of an array of strings, indicating the new values after incrementing for each matched `path`.
826
+ * If a value is not a number, its corresponding return value will be `null`.
827
+ * If `path` doesn't exist, a byte string representation of an empty array will be returned.
828
+ * - For legacy path (path doesn't start with `$`):
829
+ * - Returns a string representation of the resulting value after the increment or decrement.
830
+ * If multiple paths match, the result of the last updated value is returned.
831
+ * If the value at the `path` is not a number or `path` doesn't exist, an error is raised.
832
+ * - If `key` does not exist, an error is raised.
833
+ * - If the result is out of the range of 64-bit IEEE double, an error is raised.
834
+ *
835
+ * @example
836
+ * ```typescript
837
+ * console.log(await GlideJson.set(client, "doc", "$", '{"a": [], "b": [1], "c": [1, 2], "d": [1, 2, 3]}'));
838
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
839
+ * console.log(await GlideJson.numincrby(client, "doc", "$.d[*]", 10))
840
+ * // Output: '[11,12,13]' - Increment each element in `d` array by 10.
841
+ *
842
+ * console.log(await GlideJson.numincrby(client, "doc", ".c[1]", 10));
843
+ * // Output: '12' - Increment the second element in the `c` array by 10.
844
+ * ```
845
+ */
846
+ static async numincrby(client, key, path, num) {
847
+ const args = ["JSON.NUMINCRBY", key, path, num.toString()];
848
+ return _executeCommand(client, args);
849
+ }
850
+ /**
851
+ * Multiplies the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.
852
+ *
853
+ * @param client - The client to execute the command.
854
+ * @param key - The key of the JSON document.
855
+ * @param path - The path within the JSON document.
856
+ * @param num - The number to multiply by.
857
+ * @returns
858
+ * - For JSONPath (path starts with `$`):
859
+ * - Returns a GlideString representation of an array of strings, indicating the new values after multiplication for each matched `path`.
860
+ * If a value is not a number, its corresponding return value will be `null`.
861
+ * If `path` doesn't exist, a byte string representation of an empty array will be returned.
862
+ * - For legacy path (path doesn't start with `$`):
863
+ * - Returns a GlideString representation of the resulting value after multiplication.
864
+ * If multiple paths match, the result of the last updated value is returned.
865
+ * If the value at the `path` is not a number or `path` doesn't exist, an error is raised.
866
+ * - If `key` does not exist, an error is raised.
867
+ * - If the result is out of the range of 64-bit IEEE double, an error is raised.
868
+ *
869
+ * @example
870
+ * ```typescript
871
+ * console.log(await GlideJson.set(client, "doc", "$", '{"a": [], "b": [1], "c": [1, 2], "d": [1, 2, 3]}'));
872
+ * // Output: 'OK' - Indicates successful setting of the value at path '$' in the key stored at `doc`.
873
+ * console.log(await GlideJson.nummultby(client, "doc", "$.d[*]", 2))
874
+ * // Output: '[2,4,6]' - Multiplies each element in the `d` array by 2.
875
+ *
876
+ * console.log(await GlideJson.nummultby(client, "doc", ".c[1]", 2));
877
+ * // Output: '4' - Multiplies the second element in the `c` array by 2.
878
+ * ```
879
+ */
880
+ static async nummultby(client, key, path, num) {
881
+ const args = ["JSON.NUMMULTBY", key, path, num.toString()];
882
+ return _executeCommand(client, args);
883
+ }
884
+ /**
885
+ * Retrieves the number of key-value pairs in the object stored at the specified `path` within the JSON document stored at `key`.
886
+ *
887
+ * @param client - The client to execute the command.
888
+ * @param key - The key of the JSON document.
889
+ * @param options - (Optional) Additional parameters:
890
+ * - (Optional) `path`: The path within the JSON document, Defaults to root (`"."`) if not provided.
891
+ * @returns ReturnTypeJson<number>:
892
+ * - For JSONPath (`path` starts with `$`):
893
+ * - Returns a list of integer replies for every possible path, indicating the length of the object,
894
+ * or `null` for JSON values matching the path that are not an object.
895
+ * - If `path` doesn't exist, an empty array will be returned.
896
+ * - For legacy path (`path` doesn't starts with `$`):
897
+ * - Returns the length of the object at `path`.
898
+ * - If multiple paths match, the length of the first object match is returned.
899
+ * - If the JSON value at `path` is not an object or if `path` doesn't exist, an error is raised.
900
+ * - If `key` doesn't exist, `null` is returned.
901
+ *
902
+ * @example
903
+ * ```typescript
904
+ * console.log(await GlideJson.set(client, "doc", "$", '{"a": 1.0, "b": {"a": {"x": 1, "y": 2}, "b": 2.5, "c": true}}'));
905
+ * // Output: 'OK' - Indicates successful setting of the value at the root path '$' in the key `doc`.
906
+ * console.log(await GlideJson.objlen(client, "doc", { path: "$" }));
907
+ * // Output: [2] - Returns the number of key-value pairs at the root object, which has 2 keys: 'a' and 'b'.
908
+ * console.log(await GlideJson.objlen(client, "doc", { path: "." }));
909
+ * // Output: 2 - Returns the number of key-value pairs for the object matching the path '.', which has 2 keys: 'a' and 'b'.
910
+ * ```
911
+ */
912
+ static async objlen(client, key, options) {
913
+ const args = ["JSON.OBJLEN", key];
914
+ if (options) {
915
+ args.push(options.path);
916
+ }
917
+ return _executeCommand(client, args);
918
+ }
919
+ /**
920
+ * Retrieves key names in the object values at the specified `path` within the JSON document stored at `key`.
921
+ *
922
+ * @param client - The client to execute the command.
923
+ * @param key - The key of the JSON document.
924
+ * @param options - (Optional) Additional parameters:
925
+ * - (Optional) `path`: The path within the JSON document where the key names will be retrieved. Defaults to root (`"."`) if not provided.
926
+ * @returns ReturnTypeJson<GlideString[]>:
927
+ * - For JSONPath (`path` starts with `$`):
928
+ * - Returns a list of arrays containing key names for each matching object.
929
+ * - If a value matching the path is not an object, an empty array is returned.
930
+ * - If `path` doesn't exist, an empty array is returned.
931
+ * - For legacy path (`path` starts with `.`):
932
+ * - Returns a list of key names for the object value matching the path.
933
+ * - If multiple objects match the path, the key names of the first object is returned.
934
+ * - If a value matching the path is not an object, an error is raised.
935
+ * - If `path` doesn't exist, `null` is returned.
936
+ * - If `key` doesn't exist, `null` is returned.
937
+ *
938
+ * @example
939
+ * ```typescript
940
+ * console.log(await GlideJson.set(client, "doc", "$", '{"a": 1.0, "b": {"a": {"x": 1, "y": 2}, "b": 2.5, "c": true}}'));
941
+ * // Output: 'OK' - Indicates successful setting of the value at the root path '$' in the key `doc`.
942
+ * console.log(await GlideJson.objkeys(client, "doc", { path: "$" }));
943
+ * // Output: [["a", "b"]] - Returns a list of arrays containing the key names for objects matching the path '$'.
944
+ * console.log(await GlideJson.objkeys(client, "doc", { path: "." }));
945
+ * // Output: ["a", "b"] - Returns key names for the object matching the path '.' as it is the only match.
946
+ * ```
947
+ */
948
+ static async objkeys(client, key, options) {
949
+ const args = ["JSON.OBJKEYS", key];
950
+ if (options) {
951
+ args.push(options.path);
952
+ }
953
+ return _executeCommand(client, args, options);
954
+ }
955
+ }
956
+ exports.GlideJson = GlideJson;
957
+ /**
958
+ * Batch implementation for JSON module. Batches allow the execution of a group of
959
+ * commands in a single step. See {@link Batch} and {@link ClusterBatch}.
960
+ *
961
+ * @example
962
+ * ```typescript
963
+ * const transaction = new Batch(true);
964
+ * JsonBatch.set(transaction, "doc", ".", '{"a": 1.0, "b": 2}');
965
+ * JsonBatch.get(transaction, "doc");
966
+ * const result = await client.exec(transaction);
967
+ *
968
+ * console.log(result[0]); // Output: 'OK' - result of JsonBatch.set()
969
+ * console.log(result[1]); // Output: '{"a": 1.0, "b": 2}' - result of JsonBatch.get()
970
+ * ```
971
+ */
972
+ class JsonBatch {
973
+ /**
974
+ * Sets the JSON value at the specified `path` stored at `key`.
975
+ *
976
+ * @param batch - A batch to add commands to.
977
+ * @param key - The key of the JSON document.
978
+ * @param path - Represents the path within the JSON document where the value will be set.
979
+ * The key will be modified only if `value` is added as the last child in the specified `path`, or if the specified `path` acts as the parent of a new child being added.
980
+ * @param value - The value to set at the specific path, in JSON formatted bytes or str.
981
+ * @param options - (Optional) Additional parameters:
982
+ * - (Optional) `conditionalChange` - Set the value only if the given condition is met (within the key or path).
983
+ * Equivalent to [`XX` | `NX`] in the module API.
984
+ *
985
+ * Command Response - If the value is successfully set, returns `"OK"`.
986
+ * If `value` isn't set because of `conditionalChange`, returns `null`.
987
+ */
988
+ static set(batch, key, path, value, options) {
989
+ const args = ["JSON.SET", key, path, value];
990
+ if (options?.conditionalChange !== undefined) {
991
+ args.push(options.conditionalChange);
992
+ }
993
+ return batch.customCommand(args);
994
+ }
995
+ /**
996
+ * Retrieves the JSON value at the specified `paths` stored at `key`.
997
+ *
998
+ * @param batch - A batch to add commands to.
999
+ * @param key - The key of the JSON document.
1000
+ * @param options - (Optional) Additional parameters:
1001
+ * - (Optional) Options for formatting the byte representation of the JSON data. See {@link JsonGetOptions}.
1002
+ *
1003
+ * Command Response -
1004
+ * - If one path is given:
1005
+ * - For JSONPath (path starts with `$`):
1006
+ * - Returns a stringified JSON list of bytes replies for every possible path,
1007
+ * or a byte string representation of an empty array, if path doesn't exist.
1008
+ * If `key` doesn't exist, returns `null`.
1009
+ * - For legacy path (path doesn't start with `$`):
1010
+ * Returns a byte string representation of the value in `path`.
1011
+ * If `path` doesn't exist, an error is raised.
1012
+ * If `key` doesn't exist, returns `null`.
1013
+ * - If multiple paths are given:
1014
+ * Returns a stringified JSON object in bytes, in which each path is a key, and it's corresponding value, is the value as if the path was executed in the command as a single path.
1015
+ * In case of multiple paths, and `paths` are a mix of both JSONPath and legacy path, the command behaves as if all are JSONPath paths.
1016
+ */
1017
+ static get(batch, key, options) {
1018
+ const args = ["JSON.GET", key];
1019
+ if (options) {
1020
+ const optionArgs = _jsonGetOptionsToArgs(options);
1021
+ args.push(...optionArgs);
1022
+ }
1023
+ return batch.customCommand(args);
1024
+ }
1025
+ /**
1026
+ * Retrieves the JSON values at the specified `path` stored at multiple `keys`.
1027
+ *
1028
+ * @remarks When in cluster mode, all keys in the batch must be mapped to the same slot.
1029
+ *
1030
+ * @param client - The client to execute the command.
1031
+ * @param keys - The keys of the JSON documents.
1032
+ * @param path - The path within the JSON documents.
1033
+ *
1034
+ * Command Response -
1035
+ * - For JSONPath (path starts with `$`):
1036
+ * Returns a stringified JSON list replies for every possible path, or a string representation
1037
+ * of an empty array, if path doesn't exist.
1038
+ * - For legacy path (path doesn't start with `$`):
1039
+ * Returns a string representation of the value in `path`. If `path` doesn't exist,
1040
+ * the corresponding array element will be `null`.
1041
+ * - If a `key` doesn't exist, the corresponding array element will be `null`.
1042
+ */
1043
+ static mget(batch, keys, path) {
1044
+ const args = ["JSON.MGET", ...keys, path];
1045
+ return batch.customCommand(args);
1046
+ }
1047
+ /**
1048
+ * Inserts one or more values into the array at the specified `path` within the JSON
1049
+ * document stored at `key`, before the given `index`.
1050
+ *
1051
+ * @param batch - A batch to add commands to.
1052
+ * @param key - The key of the JSON document.
1053
+ * @param path - The path within the JSON document.
1054
+ * @param index - The array index before which values are inserted.
1055
+ * @param values - The JSON values to be inserted into the array.
1056
+ * JSON string values must be wrapped with quotes. For example, to insert `"foo"`, pass `"\"foo\""`.
1057
+ *
1058
+ * Command Response -
1059
+ * - For JSONPath (path starts with `$`):
1060
+ * Returns an array with a list of integers for every possible path,
1061
+ * indicating the new length of the array, or `null` for JSON values matching
1062
+ * the path that are not an array. If `path` does not exist, an empty array
1063
+ * will be returned.
1064
+ * - For legacy path (path doesn't start with `$`):
1065
+ * Returns an integer representing the new length of the array. If multiple paths are
1066
+ * matched, returns the length of the first modified array. If `path` doesn't
1067
+ * exist or the value at `path` is not an array, an error is raised.
1068
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
1069
+ */
1070
+ static arrinsert(batch, key, path, index, values) {
1071
+ const args = ["JSON.ARRINSERT", key, path, index.toString(), ...values];
1072
+ return batch.customCommand(args);
1073
+ }
1074
+ /**
1075
+ * Pops an element from the array located at `path` in the JSON document stored at `key`.
1076
+ *
1077
+ * @param batch - A batch to add commands to.
1078
+ * @param key - The key of the JSON document.
1079
+ * @param options - (Optional) See {@link JsonArrPopOptions}.
1080
+ *
1081
+ * Command Response -
1082
+ * - For JSONPath (path starts with `$`):
1083
+ * Returns an array with a strings for every possible path, representing the popped JSON
1084
+ * values, or `null` for JSON values matching the path that are not an array
1085
+ * or an empty array.
1086
+ * - For legacy path (path doesn't start with `$`):
1087
+ * Returns a string representing the popped JSON value, or `null` if the
1088
+ * array at `path` is empty. If multiple paths are matched, the value from
1089
+ * the first matching array that is not empty is returned. If `path` doesn't
1090
+ * exist or the value at `path` is not an array, an error is raised.
1091
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
1092
+ */
1093
+ static arrpop(batch, key, options) {
1094
+ const args = ["JSON.ARRPOP", key];
1095
+ if (options?.path)
1096
+ args.push(options?.path);
1097
+ if (options && "index" in options && options.index)
1098
+ args.push(options?.index.toString());
1099
+ return batch.customCommand(args);
1100
+ }
1101
+ /**
1102
+ * Retrieves the length of the array at the specified `path` within the JSON document stored at `key`.
1103
+ *
1104
+ * @param batch - A batch to add commands to.
1105
+ * @param key - The key of the JSON document.
1106
+ * @param options - (Optional) Additional parameters:
1107
+ * - (Optional) `path`: The path within the JSON document. Defaults to the root (`"."`) if not specified.
1108
+ *
1109
+ * Command Response -
1110
+ * - For JSONPath (path starts with `$`):
1111
+ * Returns an array with a list of integers for every possible path,
1112
+ * indicating the length of the array, or `null` for JSON values matching
1113
+ * the path that are not an array. If `path` does not exist, an empty array
1114
+ * will be returned.
1115
+ * - For legacy path (path doesn't start with `$`):
1116
+ * Returns an integer representing the length of the array. If multiple paths are
1117
+ * matched, returns the length of the first matching array. If `path` doesn't
1118
+ * exist or the value at `path` is not an array, an error is raised.
1119
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
1120
+ */
1121
+ static arrlen(batch, key, options) {
1122
+ const args = ["JSON.ARRLEN", key];
1123
+ if (options?.path)
1124
+ args.push(options?.path);
1125
+ return batch.customCommand(args);
1126
+ }
1127
+ /**
1128
+ * Trims an array at the specified `path` within the JSON document stored at `key` so that it becomes a subarray [start, end], both inclusive.
1129
+ * If `start` < 0, it is treated as 0.
1130
+ * If `end` >= size (size of the array), it is treated as size-1.
1131
+ * If `start` >= size or `start` > `end`, the array is emptied and 0 is returned.
1132
+ *
1133
+ * @param batch - A batch to add commands to.
1134
+ * @param key - The key of the JSON document.
1135
+ * @param path - The path within the JSON document.
1136
+ * @param start - The start index, inclusive.
1137
+ * @param end - The end index, inclusive.
1138
+ *
1139
+ * Command Response -
1140
+ * - For JSONPath (`path` starts with `$`):
1141
+ * - Returns a list of integer replies for every possible path, indicating the new length of the array,
1142
+ * or `null` for JSON values matching the path that are not an array.
1143
+ * - If the array is empty, its corresponding return value is 0.
1144
+ * - If `path` doesn't exist, an empty array will be returned.
1145
+ * - If an index argument is out of bounds, an error is raised.
1146
+ * - For legacy path (`path` doesn't start with `$`):
1147
+ * - Returns an integer representing the new length of the array.
1148
+ * - If the array is empty, its corresponding return value is 0.
1149
+ * - If multiple paths match, the length of the first trimmed array match is returned.
1150
+ * - If `path` doesn't exist, or the value at `path` is not an array, an error is raised.
1151
+ * - If an index argument is out of bounds, an error is raised.
1152
+ */
1153
+ static arrtrim(batch, key, path, start, end) {
1154
+ const args = [
1155
+ "JSON.ARRTRIM",
1156
+ key,
1157
+ path,
1158
+ start.toString(),
1159
+ end.toString(),
1160
+ ];
1161
+ return batch.customCommand(args);
1162
+ }
1163
+ /**
1164
+ * Searches for the first occurrence of a `scalar` JSON value in the arrays at the `path`.
1165
+ * Out of range errors are treated by rounding the index to the array's `start` and `end.
1166
+ * If `start` > `end`, return `-1` (not found).
1167
+ *
1168
+ * @param batch - A batch to add commands to.
1169
+ * @param key - The key of the JSON document.
1170
+ * @param path - The path within the JSON document.
1171
+ * @param scalar - The scalar value to search for.
1172
+ * @param options - (Optional) Additional parameters:
1173
+ * - (Optional) `start`: The start index, inclusive. Default to 0 if not provided.
1174
+ * - (Optional) `end`: The end index, exclusive. Default to 0 if not provided.
1175
+ * 0 or -1 means the last element is included.
1176
+ * Command Response -
1177
+ * - For JSONPath (path starts with `$`):
1178
+ * Returns an array with a list of integers for every possible path,
1179
+ * indicating the index of the matching element. The value is `-1` if not found.
1180
+ * If a value is not an array, its corresponding return value is `null`.
1181
+ * - For legacy path (path doesn't start with `$`):
1182
+ * Returns an integer representing the index of matching element, or `-1` if
1183
+ * not found. If the value at the `path` is not an array, an error is raised.
1184
+ */
1185
+ static arrindex(batch, key, path, scalar, options) {
1186
+ const args = ["JSON.ARRINDEX", key, path];
1187
+ if (typeof scalar === `number`) {
1188
+ args.push(scalar.toString());
1189
+ }
1190
+ else if (typeof scalar === `boolean`) {
1191
+ args.push(scalar ? `true` : `false`);
1192
+ }
1193
+ else if (scalar !== null) {
1194
+ args.push(scalar);
1195
+ }
1196
+ else {
1197
+ args.push(`null`);
1198
+ }
1199
+ if (options?.start !== undefined)
1200
+ args.push(options?.start.toString());
1201
+ if (options?.end !== undefined)
1202
+ args.push(options?.end.toString());
1203
+ return batch.customCommand(args);
1204
+ }
1205
+ /**
1206
+ * Toggles a Boolean value stored at the specified `path` within the JSON document stored at `key`.
1207
+ *
1208
+ * @param batch - A batch to add commands to.
1209
+ * @param key - The key of the JSON document.
1210
+ * @param options - (Optional) Additional parameters:
1211
+ * - (Optional) `path`: The path within the JSON document. Defaults to the root (`"."`) if not specified.
1212
+ *
1213
+ * Command Response - For JSONPath (`path` starts with `$`), returns a list of boolean replies for every possible path, with the toggled boolean value,
1214
+ * or `null` for JSON values matching the path that are not boolean.
1215
+ * - For legacy path (`path` doesn't starts with `$`), returns the value of the toggled boolean in `path`.
1216
+ * - Note that when sending legacy path syntax, If `path` doesn't exist or the value at `path` isn't a boolean, an error is raised.
1217
+ */
1218
+ static toggle(batch, key, options) {
1219
+ const args = ["JSON.TOGGLE", key];
1220
+ if (options) {
1221
+ args.push(options.path);
1222
+ }
1223
+ return batch.customCommand(args);
1224
+ }
1225
+ /**
1226
+ * Deletes the JSON value at the specified `path` within the JSON document stored at `key`.
1227
+ *
1228
+ * @param batch - A batch to add commands to.
1229
+ * @param key - The key of the JSON document.
1230
+ * @param options - (Optional) Additional parameters:
1231
+ * - (Optional) `path`: If `null`, deletes the entire JSON document at `key`.
1232
+ *
1233
+ * Command Response - The number of elements removed. If `key` or `path` doesn't exist, returns 0.
1234
+ */
1235
+ static del(batch, key, options) {
1236
+ const args = ["JSON.DEL", key];
1237
+ if (options) {
1238
+ args.push(options.path);
1239
+ }
1240
+ return batch.customCommand(args);
1241
+ }
1242
+ /**
1243
+ * Deletes the JSON value at the specified `path` within the JSON document stored at `key`. This command is
1244
+ * an alias of {@link del}.
1245
+ *
1246
+ * @param batch - A batch to add commands to.
1247
+ * @param key - The key of the JSON document.
1248
+ * @param options - (Optional) Additional parameters:
1249
+ * - (Optional) `path`: If `null`, deletes the entire JSON document at `key`.
1250
+ *
1251
+ * Command Response - The number of elements removed. If `key` or `path` doesn't exist, returns 0.
1252
+ */
1253
+ static forget(batch, key, options) {
1254
+ const args = ["JSON.FORGET", key];
1255
+ if (options) {
1256
+ args.push(options.path);
1257
+ }
1258
+ return batch.customCommand(args);
1259
+ }
1260
+ /**
1261
+ * Reports the type of values at the given path.
1262
+ *
1263
+ * @param batch - A batch to add commands to.
1264
+ * @param key - The key of the JSON document.
1265
+ * @param options - (Optional) Additional parameters:
1266
+ * - (Optional) `path`: Defaults to root (`"."`) if not provided.
1267
+ *
1268
+ * Command Response -
1269
+ * - For JSONPath (path starts with `$`):
1270
+ * - Returns an array of strings that represents the type of value at each path.
1271
+ * The type is one of "null", "boolean", "string", "number", "integer", "object" and "array".
1272
+ * - If a path does not exist, its corresponding return value is `null`.
1273
+ * - Empty array if the document key does not exist.
1274
+ * - For legacy path (path doesn't start with `$`):
1275
+ * - String that represents the type of the value.
1276
+ * - `null` if the document key does not exist.
1277
+ * - `null` if the JSON path is invalid or does not exist.
1278
+ */
1279
+ static type(batch, key, options) {
1280
+ const args = ["JSON.TYPE", key];
1281
+ if (options) {
1282
+ args.push(options.path);
1283
+ }
1284
+ return batch.customCommand(args);
1285
+ }
1286
+ /**
1287
+ * Clears arrays or objects at the specified JSON path in the document stored at `key`.
1288
+ * Numeric values are set to `0`, boolean values are set to `false`, and string values are converted to empty strings.
1289
+ *
1290
+ * @param batch - A batch to add commands to.
1291
+ * @param key - The key of the JSON document.
1292
+ * @param options - (Optional) Additional parameters:
1293
+ * - (Optional) `path`: The JSON path to the arrays or objects to be cleared. Defaults to root if not provided.
1294
+ *
1295
+ * Command Response - The number of containers cleared, numeric values zeroed, and booleans toggled to `false`,
1296
+ * and string values converted to empty strings.
1297
+ * If `path` doesn't exist, or the value at `path` is already empty (e.g., an empty array, object, or string), `0` is returned.
1298
+ * If `key doesn't exist, an error is raised.
1299
+ */
1300
+ static clear(batch, key, options) {
1301
+ const args = ["JSON.CLEAR", key];
1302
+ if (options) {
1303
+ args.push(options.path);
1304
+ }
1305
+ return batch.customCommand(args);
1306
+ }
1307
+ /**
1308
+ * Retrieve the JSON value at the specified `path` within the JSON document stored at `key`.
1309
+ * The returning result is in the Valkey or Redis OSS Serialization Protocol (RESP).
1310
+ * - JSON null is mapped to the RESP Null Bulk String.
1311
+ * - JSON Booleans are mapped to RESP Simple string.
1312
+ * - JSON integers are mapped to RESP Integers.
1313
+ * - JSON doubles are mapped to RESP Bulk Strings.
1314
+ * - JSON strings are mapped to RESP Bulk Strings.
1315
+ * - JSON arrays are represented as RESP arrays, where the first element is the simple string [, followed by the array's elements.
1316
+ * - JSON objects are represented as RESP object, where the first element is the simple string {, followed by key-value pairs, each of which is a RESP bulk string.
1317
+ *
1318
+ * @param batch - A batch to add commands to.
1319
+ * @param key - The key of the JSON document.
1320
+ * @param options - (Optional) Additional parameters:
1321
+ * - (Optional) `path`: The path within the JSON document, defaults to root (`"."`) if not provided.
1322
+ *
1323
+ * Command Response -
1324
+ * - For JSONPath (path starts with `$`):
1325
+ * - Returns an array of replies for every possible path, indicating the RESP form of the JSON value.
1326
+ * If `path` doesn't exist, returns an empty array.
1327
+ * - For legacy path (path doesn't start with `$`):
1328
+ * - Returns a single reply for the JSON value at the specified `path`, in its RESP form.
1329
+ * If multiple paths match, the value of the first JSON value match is returned. If `path` doesn't exist, an error is raised.
1330
+ * - If `key` doesn't exist, `null` is returned.
1331
+ */
1332
+ static resp(batch, key, options) {
1333
+ const args = ["JSON.RESP", key];
1334
+ if (options) {
1335
+ args.push(options.path);
1336
+ }
1337
+ return batch.customCommand(args);
1338
+ }
1339
+ /**
1340
+ * Returns the length of the JSON string value stored at the specified `path` within
1341
+ * the JSON document stored at `key`.
1342
+ *
1343
+ * @param batch - A batch to add commands to.
1344
+ * @param key - The key of the JSON document.
1345
+ * @param options - (Optional) Additional parameters:
1346
+ * - (Optional) `path`: The path within the JSON document, Defaults to root (`"."`) if not provided.
1347
+ *
1348
+ * Command Response -
1349
+ * - For JSONPath (path starts with `$`):
1350
+ * - Returns a list of integer replies for every possible path, indicating the length of
1351
+ * the JSON string value, or <code>null</code> for JSON values matching the path that
1352
+ * are not string.
1353
+ * - For legacy path (path doesn't start with `$`):
1354
+ * - Returns the length of the JSON value at `path` or `null` if `key` doesn't exist.
1355
+ * - If multiple paths match, the length of the first matched string is returned.
1356
+ * - If the JSON value at`path` is not a string or if `path` doesn't exist, an error is raised.
1357
+ * - If `key` doesn't exist, `null` is returned.
1358
+ */
1359
+ static strlen(batch, key, options) {
1360
+ const args = ["JSON.STRLEN", key];
1361
+ if (options) {
1362
+ args.push(options.path);
1363
+ }
1364
+ return batch.customCommand(args);
1365
+ }
1366
+ /**
1367
+ * Appends the specified `value` to the string stored at the specified `path` within the JSON document stored at `key`.
1368
+ *
1369
+ * @param batch - A batch to add commands to.
1370
+ * @param key - The key of the JSON document.
1371
+ * @param value - The value to append to the string. Must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
1372
+ * @param options - (Optional) Additional parameters:
1373
+ * - (Optional) `path`: The path within the JSON document, defaults to root (`"."`) if not provided.
1374
+ *
1375
+ * Command Response -
1376
+ * - For JSONPath (path starts with `$`):
1377
+ * - Returns a list of integer replies for every possible path, indicating the length of the resulting string after appending `value`,
1378
+ * or None for JSON values matching the path that are not string.
1379
+ * - If `key` doesn't exist, an error is raised.
1380
+ * - For legacy path (path doesn't start with `$`):
1381
+ * - Returns the length of the resulting string after appending `value` to the string at `path`.
1382
+ * - If multiple paths match, the length of the last updated string is returned.
1383
+ * - If the JSON value at `path` is not a string of if `path` doesn't exist, an error is raised.
1384
+ * - If `key` doesn't exist, an error is raised.
1385
+ */
1386
+ static strappend(batch, key, value, options) {
1387
+ const args = ["JSON.STRAPPEND", key];
1388
+ if (options) {
1389
+ args.push(options.path);
1390
+ }
1391
+ args.push(value);
1392
+ return batch.customCommand(args);
1393
+ }
1394
+ /**
1395
+ * Appends one or more `values` to the JSON array at the specified `path` within the JSON
1396
+ * document stored at `key`.
1397
+ *
1398
+ * @param batch - A batch to add commands to.
1399
+ * @param key - The key of the JSON document.
1400
+ * @param path - The path within the JSON document.
1401
+ * @param values - The JSON values to be appended to the array.
1402
+ * JSON string values must be wrapped with quotes. For example, to append `"foo"`, pass `"\"foo\""`.
1403
+ *
1404
+ * Command Response -
1405
+ * - For JSONPath (path starts with `$`):
1406
+ * Returns an array with a list of integers for every possible path,
1407
+ * indicating the new length of the array, or `null` for JSON values matching
1408
+ * the path that are not an array. If `path` does not exist, an empty array
1409
+ * will be returned.
1410
+ * - For legacy path (path doesn't start with `$`):
1411
+ * Returns an integer representing the new length of the array. If multiple paths are
1412
+ * matched, returns the length of the first modified array. If `path` doesn't
1413
+ * exist or the value at `path` is not an array, an error is raised.
1414
+ * - If the index is out of bounds or `key` doesn't exist, an error is raised.
1415
+ */
1416
+ static arrappend(batch, key, path, values) {
1417
+ const args = ["JSON.ARRAPPEND", key, path, ...values];
1418
+ return batch.customCommand(args);
1419
+ }
1420
+ /**
1421
+ * Reports memory usage in bytes of a JSON object at the specified `path` within the JSON document stored at `key`.
1422
+ *
1423
+ * @param batch - A batch to add commands to.
1424
+ * @param key - The key of the JSON document.
1425
+ * @param value - The value to append to the string. Must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
1426
+ * @param options - (Optional) Additional parameters:
1427
+ * - (Optional) `path`: The path within the JSON document, returns total memory usage if no path is given.
1428
+ *
1429
+ * Command Response -
1430
+ * - For JSONPath (path starts with `$`):
1431
+ * - Returns an array of numbers for every possible path, indicating the memory usage.
1432
+ * If `path` does not exist, an empty array will be returned.
1433
+ * - For legacy path (path doesn't start with `$`):
1434
+ * - Returns an integer representing the memory usage. If multiple paths are matched,
1435
+ * returns the data of the first matching object. If `path` doesn't exist, an error is raised.
1436
+ * - If `key` doesn't exist, returns `null`.
1437
+ */
1438
+ static debugMemory(batch, key, options) {
1439
+ const args = ["JSON.DEBUG", "MEMORY", key];
1440
+ if (options) {
1441
+ args.push(options.path);
1442
+ }
1443
+ return batch.customCommand(args);
1444
+ }
1445
+ /**
1446
+ * Reports the number of fields at the specified `path` within the JSON document stored at `key`.
1447
+ *
1448
+ * @param batch - A batch to add commands to.
1449
+ * @param key - The key of the JSON document.
1450
+ * @param value - The value to append to the string. Must be wrapped with single quotes. For example, to append "foo", pass '"foo"'.
1451
+ * @param options - (Optional) Additional parameters:
1452
+ * - (Optional) `path`: The path within the JSON document, returns total number of fields if no path is given.
1453
+ *
1454
+ * Command Response -
1455
+ * - For JSONPath (path starts with `$`):
1456
+ * - Returns an array of numbers for every possible path, indicating the number of fields.
1457
+ * If `path` does not exist, an empty array will be returned.
1458
+ * - For legacy path (path doesn't start with `$`):
1459
+ * - Returns an integer representing the memory usage. If multiple paths are matched,
1460
+ * returns the data of the first matching object. If `path` doesn't exist, an error is raised.
1461
+ * - If `key` doesn't exist, returns `null`.
1462
+ */
1463
+ static debugFields(batch, key, options) {
1464
+ const args = ["JSON.DEBUG", "FIELDS", key];
1465
+ if (options) {
1466
+ args.push(options.path);
1467
+ }
1468
+ return batch.customCommand(args);
1469
+ }
1470
+ /**
1471
+ * Increments or decrements the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.
1472
+ *
1473
+ * @param batch - A batch to add commands to.
1474
+ * @param key - The key of the JSON document.
1475
+ * @param path - The path within the JSON document.
1476
+ * @param num - The number to increment or decrement by.
1477
+ *
1478
+ * Command Response -
1479
+ * - For JSONPath (path starts with `$`):
1480
+ * - Returns a string representation of an array of strings, indicating the new values after incrementing for each matched `path`.
1481
+ * If a value is not a number, its corresponding return value will be `null`.
1482
+ * If `path` doesn't exist, a byte string representation of an empty array will be returned.
1483
+ * - For legacy path (path doesn't start with `$`):
1484
+ * - Returns a string representation of the resulting value after the increment or decrement.
1485
+ * If multiple paths match, the result of the last updated value is returned.
1486
+ * If the value at the `path` is not a number or `path` doesn't exist, an error is raised.
1487
+ * - If `key` does not exist, an error is raised.
1488
+ * - If the result is out of the range of 64-bit IEEE double, an error is raised.
1489
+ */
1490
+ static numincrby(batch, key, path, num) {
1491
+ const args = ["JSON.NUMINCRBY", key, path, num.toString()];
1492
+ return batch.customCommand(args);
1493
+ }
1494
+ /**
1495
+ * Multiplies the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.
1496
+ *
1497
+ * @param batch - A batch to add commands to.
1498
+ * @param key - The key of the JSON document.
1499
+ * @param path - The path within the JSON document.
1500
+ * @param num - The number to multiply by.
1501
+ *
1502
+ * Command Response -
1503
+ * - For JSONPath (path starts with `$`):
1504
+ * - Returns a GlideString representation of an array of strings, indicating the new values after multiplication for each matched `path`.
1505
+ * If a value is not a number, its corresponding return value will be `null`.
1506
+ * If `path` doesn't exist, a byte string representation of an empty array will be returned.
1507
+ * - For legacy path (path doesn't start with `$`):
1508
+ * - Returns a GlideString representation of the resulting value after multiplication.
1509
+ * If multiple paths match, the result of the last updated value is returned.
1510
+ * If the value at the `path` is not a number or `path` doesn't exist, an error is raised.
1511
+ * - If `key` does not exist, an error is raised.
1512
+ * - If the result is out of the range of 64-bit IEEE double, an error is raised.
1513
+ */
1514
+ static nummultby(batch, key, path, num) {
1515
+ const args = ["JSON.NUMMULTBY", key, path, num.toString()];
1516
+ return batch.customCommand(args);
1517
+ }
1518
+ /**
1519
+ * Retrieves the number of key-value pairs in the object stored at the specified `path` within the JSON document stored at `key`.
1520
+ *
1521
+ * @param batch - A batch to add commands to.
1522
+ * @param key - The key of the JSON document.
1523
+ * @param options - (Optional) Additional parameters:
1524
+ * - (Optional) `path`: The path within the JSON document, Defaults to root (`"."`) if not provided.
1525
+ *
1526
+ * Command Response - ReturnTypeJson<number>:
1527
+ * - For JSONPath (`path` starts with `$`):
1528
+ * - Returns a list of integer replies for every possible path, indicating the length of the object,
1529
+ * or `null` for JSON values matching the path that are not an object.
1530
+ * - If `path` doesn't exist, an empty array will be returned.
1531
+ * - For legacy path (`path` doesn't starts with `$`):
1532
+ * - Returns the length of the object at `path`.
1533
+ * - If multiple paths match, the length of the first object match is returned.
1534
+ * - If the JSON value at `path` is not an object or if `path` doesn't exist, an error is raised.
1535
+ * - If `key` doesn't exist, `null` is returned.
1536
+ */
1537
+ static objlen(batch, key, options) {
1538
+ const args = ["JSON.OBJLEN", key];
1539
+ if (options) {
1540
+ args.push(options.path);
1541
+ }
1542
+ return batch.customCommand(args);
1543
+ }
1544
+ /**
1545
+ * Retrieves key names in the object values at the specified `path` within the JSON document stored at `key`.
1546
+ *
1547
+ * @param batch - A batch to add commands to.
1548
+ * @param key - The key of the JSON document.
1549
+ * @param options - (Optional) Additional parameters:
1550
+ * - (Optional) `path`: The path within the JSON document where the key names will be retrieved. Defaults to root (`"."`) if not provided.
1551
+ *
1552
+ * Command Response - ReturnTypeJson<GlideString[]>:
1553
+ * - For JSONPath (`path` starts with `$`):
1554
+ * - Returns a list of arrays containing key names for each matching object.
1555
+ * - If a value matching the path is not an object, an empty array is returned.
1556
+ * - If `path` doesn't exist, an empty array is returned.
1557
+ * - For legacy path (`path` starts with `.`):
1558
+ * - Returns a list of key names for the object value matching the path.
1559
+ * - If multiple objects match the path, the key names of the first object is returned.
1560
+ * - If a value matching the path is not an object, an error is raised.
1561
+ * - If `path` doesn't exist, `null` is returned.
1562
+ * - If `key` doesn't exist, `null` is returned.
1563
+ */
1564
+ static objkeys(batch, key, options) {
1565
+ const args = ["JSON.OBJKEYS", key];
1566
+ if (options) {
1567
+ args.push(options.path);
1568
+ }
1569
+ return batch.customCommand(args);
1570
+ }
1571
+ }
1572
+ exports.JsonBatch = JsonBatch;
1573
+ //# sourceMappingURL=GlideJson.js.map