@valkey/valkey-glide-darwin-x64 1.3.4 → 255.255.255

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