@upstash/redis 0.0.0-ci.d3170677a5859e31d40407781286bdf17d64ca72-20250220114636 → 0.0.0-ci.d3985e1d3f7f296ee10dff2746b51fa88dddc9a9-20251222113217
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.
- package/README.md +9 -0
- package/{chunk-AQ2U77ZI.mjs → chunk-LU3F3BSG.mjs} +667 -74
- package/cloudflare.d.mts +3 -3
- package/cloudflare.d.ts +3 -3
- package/cloudflare.js +683 -96
- package/cloudflare.mjs +15 -11
- package/fastly.d.mts +2 -2
- package/fastly.d.ts +2 -2
- package/fastly.js +669 -86
- package/fastly.mjs +1 -1
- package/nodejs.d.mts +14 -6
- package/nodejs.d.ts +14 -6
- package/nodejs.js +681 -92
- package/nodejs.mjs +13 -7
- package/package.json +1 -1
- package/{zmscore-BnJuTB6j.d.mts → zmscore-CSYwsf1L.d.mts} +515 -57
- package/{zmscore-BnJuTB6j.d.ts → zmscore-CSYwsf1L.d.ts} +515 -57
package/nodejs.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// platforms/nodejs.ts
|
|
@@ -39,11 +29,12 @@ module.exports = __toCommonJS(nodejs_exports);
|
|
|
39
29
|
var error_exports = {};
|
|
40
30
|
__export(error_exports, {
|
|
41
31
|
UpstashError: () => UpstashError,
|
|
32
|
+
UpstashJSONParseError: () => UpstashJSONParseError,
|
|
42
33
|
UrlError: () => UrlError
|
|
43
34
|
});
|
|
44
35
|
var UpstashError = class extends Error {
|
|
45
|
-
constructor(message) {
|
|
46
|
-
super(message);
|
|
36
|
+
constructor(message, options) {
|
|
37
|
+
super(message, options);
|
|
47
38
|
this.name = "UpstashError";
|
|
48
39
|
}
|
|
49
40
|
};
|
|
@@ -55,6 +46,13 @@ var UrlError = class extends Error {
|
|
|
55
46
|
this.name = "UrlError";
|
|
56
47
|
}
|
|
57
48
|
};
|
|
49
|
+
var UpstashJSONParseError = class extends UpstashError {
|
|
50
|
+
constructor(body, options) {
|
|
51
|
+
const truncatedBody = body.length > 200 ? body.slice(0, 200) + "..." : body;
|
|
52
|
+
super(`Unable to parse response body: ${truncatedBody}`, options);
|
|
53
|
+
this.name = "UpstashJSONParseError";
|
|
54
|
+
}
|
|
55
|
+
};
|
|
58
56
|
|
|
59
57
|
// pkg/util.ts
|
|
60
58
|
function parseRecursive(obj) {
|
|
@@ -80,6 +78,14 @@ function parseResponse(result) {
|
|
|
80
78
|
function deserializeScanResponse(result) {
|
|
81
79
|
return [result[0], ...parseResponse(result.slice(1))];
|
|
82
80
|
}
|
|
81
|
+
function deserializeScanWithTypesResponse(result) {
|
|
82
|
+
const [cursor, keys] = result;
|
|
83
|
+
const parsedKeys = [];
|
|
84
|
+
for (let i = 0; i < keys.length; i += 2) {
|
|
85
|
+
parsedKeys.push({ key: keys[i], type: keys[i + 1] });
|
|
86
|
+
}
|
|
87
|
+
return [cursor, parsedKeys];
|
|
88
|
+
}
|
|
83
89
|
function mergeHeaders(...headers) {
|
|
84
90
|
const merged = {};
|
|
85
91
|
for (const header of headers) {
|
|
@@ -92,6 +98,15 @@ function mergeHeaders(...headers) {
|
|
|
92
98
|
}
|
|
93
99
|
return merged;
|
|
94
100
|
}
|
|
101
|
+
function kvArrayToObject(v) {
|
|
102
|
+
if (typeof v === "object" && v !== null && !Array.isArray(v)) return v;
|
|
103
|
+
if (!Array.isArray(v)) return {};
|
|
104
|
+
const obj = {};
|
|
105
|
+
for (let i = 0; i < v.length; i += 2) {
|
|
106
|
+
if (typeof v[i] === "string") obj[v[i]] = v[i + 1];
|
|
107
|
+
}
|
|
108
|
+
return obj;
|
|
109
|
+
}
|
|
95
110
|
|
|
96
111
|
// pkg/http.ts
|
|
97
112
|
var HttpClient = class {
|
|
@@ -144,6 +159,8 @@ var HttpClient = class {
|
|
|
144
159
|
const requestHeaders = mergeHeaders(this.headers, req.headers ?? {});
|
|
145
160
|
const requestUrl = [this.baseUrl, ...req.path ?? []].join("/");
|
|
146
161
|
const isEventStream = requestHeaders.Accept === "text/event-stream";
|
|
162
|
+
const signal = req.signal ?? this.options.signal;
|
|
163
|
+
const isSignalFunction = typeof signal === "function";
|
|
147
164
|
const requestOptions = {
|
|
148
165
|
//@ts-expect-error this should throw due to bun regression
|
|
149
166
|
cache: this.options.cache,
|
|
@@ -152,7 +169,7 @@ var HttpClient = class {
|
|
|
152
169
|
body: JSON.stringify(req.body),
|
|
153
170
|
keepalive: this.options.keepAlive,
|
|
154
171
|
agent: this.options.agent,
|
|
155
|
-
signal:
|
|
172
|
+
signal: isSignalFunction ? signal() : signal,
|
|
156
173
|
/**
|
|
157
174
|
* Fastly specific
|
|
158
175
|
*/
|
|
@@ -174,13 +191,15 @@ var HttpClient = class {
|
|
|
174
191
|
res = await fetch(requestUrl, requestOptions);
|
|
175
192
|
break;
|
|
176
193
|
} catch (error_) {
|
|
177
|
-
if (
|
|
194
|
+
if (requestOptions.signal?.aborted && isSignalFunction) {
|
|
195
|
+
throw error_;
|
|
196
|
+
} else if (requestOptions.signal?.aborted) {
|
|
178
197
|
const myBlob = new Blob([
|
|
179
|
-
JSON.stringify({ result:
|
|
198
|
+
JSON.stringify({ result: requestOptions.signal.reason ?? "Aborted" })
|
|
180
199
|
]);
|
|
181
200
|
const myOptions = {
|
|
182
201
|
status: 200,
|
|
183
|
-
statusText:
|
|
202
|
+
statusText: requestOptions.signal.reason ?? "Aborted"
|
|
184
203
|
};
|
|
185
204
|
res = new Response(myBlob, myOptions);
|
|
186
205
|
break;
|
|
@@ -195,7 +214,13 @@ var HttpClient = class {
|
|
|
195
214
|
throw error ?? new Error("Exhausted all retries");
|
|
196
215
|
}
|
|
197
216
|
if (!res.ok) {
|
|
198
|
-
|
|
217
|
+
let body2;
|
|
218
|
+
const rawBody2 = await res.text();
|
|
219
|
+
try {
|
|
220
|
+
body2 = JSON.parse(rawBody2);
|
|
221
|
+
} catch (error2) {
|
|
222
|
+
throw new UpstashJSONParseError(rawBody2, { cause: error2 });
|
|
223
|
+
}
|
|
199
224
|
throw new UpstashError(`${body2.error}, command was: ${JSON.stringify(req.body)}`);
|
|
200
225
|
}
|
|
201
226
|
if (this.readYourWrites) {
|
|
@@ -233,7 +258,13 @@ var HttpClient = class {
|
|
|
233
258
|
})();
|
|
234
259
|
return { result: 1 };
|
|
235
260
|
}
|
|
236
|
-
|
|
261
|
+
let body;
|
|
262
|
+
const rawBody = await res.text();
|
|
263
|
+
try {
|
|
264
|
+
body = JSON.parse(rawBody);
|
|
265
|
+
} catch (error2) {
|
|
266
|
+
throw new UpstashJSONParseError(rawBody, { cause: error2 });
|
|
267
|
+
}
|
|
237
268
|
if (this.readYourWrites) {
|
|
238
269
|
const headers = res.headers;
|
|
239
270
|
this.upstashSyncToken = headers.get("upstash-sync-token") ?? "";
|
|
@@ -305,7 +336,25 @@ function merge(obj, key, value) {
|
|
|
305
336
|
}
|
|
306
337
|
|
|
307
338
|
// pkg/auto-pipeline.ts
|
|
308
|
-
|
|
339
|
+
var EXCLUDE_COMMANDS = /* @__PURE__ */ new Set([
|
|
340
|
+
"scan",
|
|
341
|
+
"keys",
|
|
342
|
+
"flushdb",
|
|
343
|
+
"flushall",
|
|
344
|
+
"dbsize",
|
|
345
|
+
"hscan",
|
|
346
|
+
"hgetall",
|
|
347
|
+
"hkeys",
|
|
348
|
+
"lrange",
|
|
349
|
+
"sscan",
|
|
350
|
+
"smembers",
|
|
351
|
+
"xrange",
|
|
352
|
+
"xrevrange",
|
|
353
|
+
"zscan",
|
|
354
|
+
"zrange",
|
|
355
|
+
"exec"
|
|
356
|
+
]);
|
|
357
|
+
function createAutoPipelineProxy(_redis, namespace = "root") {
|
|
309
358
|
const redis = _redis;
|
|
310
359
|
if (!redis.autoPipelineExecutor) {
|
|
311
360
|
redis.autoPipelineExecutor = new AutoPipelineExecutor(redis);
|
|
@@ -315,28 +364,31 @@ function createAutoPipelineProxy(_redis, json) {
|
|
|
315
364
|
if (command === "pipelineCounter") {
|
|
316
365
|
return redis2.autoPipelineExecutor.pipelineCounter;
|
|
317
366
|
}
|
|
318
|
-
if (command === "json") {
|
|
319
|
-
return createAutoPipelineProxy(redis2,
|
|
367
|
+
if (namespace === "root" && command === "json") {
|
|
368
|
+
return createAutoPipelineProxy(redis2, "json");
|
|
320
369
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
370
|
+
if (namespace === "root" && command === "functions") {
|
|
371
|
+
return createAutoPipelineProxy(redis2, "functions");
|
|
372
|
+
}
|
|
373
|
+
if (namespace === "root") {
|
|
374
|
+
const commandInRedisButNotPipeline = command in redis2 && !(command in redis2.autoPipelineExecutor.pipeline);
|
|
375
|
+
const isCommandExcluded = EXCLUDE_COMMANDS.has(command);
|
|
376
|
+
if (commandInRedisButNotPipeline || isCommandExcluded) {
|
|
377
|
+
return redis2[command];
|
|
378
|
+
}
|
|
324
379
|
}
|
|
325
|
-
const
|
|
380
|
+
const pipeline = redis2.autoPipelineExecutor.pipeline;
|
|
381
|
+
const targetFunction = namespace === "json" ? pipeline.json[command] : namespace === "functions" ? pipeline.functions[command] : pipeline[command];
|
|
382
|
+
const isFunction = typeof targetFunction === "function";
|
|
326
383
|
if (isFunction) {
|
|
327
384
|
return (...args) => {
|
|
328
|
-
return redis2.autoPipelineExecutor.withAutoPipeline((
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
...args
|
|
332
|
-
);
|
|
333
|
-
} else {
|
|
334
|
-
pipeline[command](...args);
|
|
335
|
-
}
|
|
385
|
+
return redis2.autoPipelineExecutor.withAutoPipeline((pipeline2) => {
|
|
386
|
+
const targetFunction2 = namespace === "json" ? pipeline2.json[command] : namespace === "functions" ? pipeline2.functions[command] : pipeline2[command];
|
|
387
|
+
targetFunction2(...args);
|
|
336
388
|
});
|
|
337
389
|
};
|
|
338
390
|
}
|
|
339
|
-
return
|
|
391
|
+
return targetFunction;
|
|
340
392
|
}
|
|
341
393
|
});
|
|
342
394
|
}
|
|
@@ -572,6 +624,13 @@ var EchoCommand = class extends Command {
|
|
|
572
624
|
}
|
|
573
625
|
};
|
|
574
626
|
|
|
627
|
+
// pkg/commands/evalRo.ts
|
|
628
|
+
var EvalROCommand = class extends Command {
|
|
629
|
+
constructor([script, keys, args], opts) {
|
|
630
|
+
super(["eval_ro", script, keys.length, ...keys, ...args ?? []], opts);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
|
|
575
634
|
// pkg/commands/eval.ts
|
|
576
635
|
var EvalCommand = class extends Command {
|
|
577
636
|
constructor([script, keys, args], opts) {
|
|
@@ -579,6 +638,13 @@ var EvalCommand = class extends Command {
|
|
|
579
638
|
}
|
|
580
639
|
};
|
|
581
640
|
|
|
641
|
+
// pkg/commands/evalshaRo.ts
|
|
642
|
+
var EvalshaROCommand = class extends Command {
|
|
643
|
+
constructor([sha, keys, args], opts) {
|
|
644
|
+
super(["evalsha_ro", sha, keys.length, ...keys, ...args ?? []], opts);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
|
|
582
648
|
// pkg/commands/evalsha.ts
|
|
583
649
|
var EvalshaCommand = class extends Command {
|
|
584
650
|
constructor([sha, keys, args], opts) {
|
|
@@ -615,6 +681,20 @@ var ExpireAtCommand = class extends Command {
|
|
|
615
681
|
}
|
|
616
682
|
};
|
|
617
683
|
|
|
684
|
+
// pkg/commands/fcall.ts
|
|
685
|
+
var FCallCommand = class extends Command {
|
|
686
|
+
constructor([fn, keys, args], opts) {
|
|
687
|
+
super(["fcall", fn, ...keys ? [keys.length, ...keys] : [0], ...args ?? []], opts);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
// pkg/commands/fcall_ro.ts
|
|
692
|
+
var FCallRoCommand = class extends Command {
|
|
693
|
+
constructor([fn, keys, args], opts) {
|
|
694
|
+
super(["fcall_ro", fn, ...keys ? [keys.length, ...keys] : [], ...args ?? []], opts);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
|
|
618
698
|
// pkg/commands/flushall.ts
|
|
619
699
|
var FlushAllCommand = class extends Command {
|
|
620
700
|
constructor(args, opts) {
|
|
@@ -637,6 +717,85 @@ var FlushDBCommand = class extends Command {
|
|
|
637
717
|
}
|
|
638
718
|
};
|
|
639
719
|
|
|
720
|
+
// pkg/commands/function_delete.ts
|
|
721
|
+
var FunctionDeleteCommand = class extends Command {
|
|
722
|
+
constructor([libraryName], opts) {
|
|
723
|
+
super(["function", "delete", libraryName], opts);
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
// pkg/commands/function_flush.ts
|
|
728
|
+
var FunctionFlushCommand = class extends Command {
|
|
729
|
+
constructor(opts) {
|
|
730
|
+
super(["function", "flush"], opts);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
// pkg/commands/function_list.ts
|
|
735
|
+
var FunctionListCommand = class extends Command {
|
|
736
|
+
constructor([args], opts) {
|
|
737
|
+
const command = ["function", "list"];
|
|
738
|
+
if (args?.libraryName) {
|
|
739
|
+
command.push("libraryname", args.libraryName);
|
|
740
|
+
}
|
|
741
|
+
if (args?.withCode) {
|
|
742
|
+
command.push("withcode");
|
|
743
|
+
}
|
|
744
|
+
super(command, { deserialize, ...opts });
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
function deserialize(result) {
|
|
748
|
+
if (!Array.isArray(result)) return [];
|
|
749
|
+
return result.map((libRaw) => {
|
|
750
|
+
const lib = kvArrayToObject(libRaw);
|
|
751
|
+
const functionsParsed = lib.functions.map(
|
|
752
|
+
(fnRaw) => kvArrayToObject(fnRaw)
|
|
753
|
+
);
|
|
754
|
+
return {
|
|
755
|
+
libraryName: lib.library_name,
|
|
756
|
+
engine: lib.engine,
|
|
757
|
+
functions: functionsParsed.map((fn) => ({
|
|
758
|
+
name: fn.name,
|
|
759
|
+
description: fn.description ?? void 0,
|
|
760
|
+
flags: fn.flags
|
|
761
|
+
})),
|
|
762
|
+
libraryCode: lib.library_code
|
|
763
|
+
};
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// pkg/commands/function_load.ts
|
|
768
|
+
var FunctionLoadCommand = class extends Command {
|
|
769
|
+
constructor([args], opts) {
|
|
770
|
+
super(["function", "load", ...args.replace ? ["replace"] : [], args.code], opts);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
// pkg/commands/function_stats.ts
|
|
775
|
+
var FunctionStatsCommand = class extends Command {
|
|
776
|
+
constructor(opts) {
|
|
777
|
+
super(["function", "stats"], { deserialize: deserialize2, ...opts });
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
function deserialize2(result) {
|
|
781
|
+
const rawEngines = kvArrayToObject(kvArrayToObject(result).engines);
|
|
782
|
+
const parsedEngines = Object.fromEntries(
|
|
783
|
+
Object.entries(rawEngines).map(([key, value]) => [key, kvArrayToObject(value)])
|
|
784
|
+
);
|
|
785
|
+
const final = {
|
|
786
|
+
engines: Object.fromEntries(
|
|
787
|
+
Object.entries(parsedEngines).map(([key, value]) => [
|
|
788
|
+
key,
|
|
789
|
+
{
|
|
790
|
+
librariesCount: value.libraries_count,
|
|
791
|
+
functionsCount: value.functions_count
|
|
792
|
+
}
|
|
793
|
+
])
|
|
794
|
+
)
|
|
795
|
+
};
|
|
796
|
+
return final;
|
|
797
|
+
}
|
|
798
|
+
|
|
640
799
|
// pkg/commands/geo_add.ts
|
|
641
800
|
var GeoAddCommand = class extends Command {
|
|
642
801
|
constructor([key, arg1, ...arg2], opts) {
|
|
@@ -859,6 +1018,122 @@ var HExistsCommand = class extends Command {
|
|
|
859
1018
|
}
|
|
860
1019
|
};
|
|
861
1020
|
|
|
1021
|
+
// pkg/commands/hexpire.ts
|
|
1022
|
+
var HExpireCommand = class extends Command {
|
|
1023
|
+
constructor(cmd, opts) {
|
|
1024
|
+
const [key, fields, seconds, option] = cmd;
|
|
1025
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1026
|
+
super(
|
|
1027
|
+
[
|
|
1028
|
+
"hexpire",
|
|
1029
|
+
key,
|
|
1030
|
+
seconds,
|
|
1031
|
+
...option ? [option] : [],
|
|
1032
|
+
"FIELDS",
|
|
1033
|
+
fieldArray.length,
|
|
1034
|
+
...fieldArray
|
|
1035
|
+
],
|
|
1036
|
+
opts
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
// pkg/commands/hexpireat.ts
|
|
1042
|
+
var HExpireAtCommand = class extends Command {
|
|
1043
|
+
constructor(cmd, opts) {
|
|
1044
|
+
const [key, fields, timestamp, option] = cmd;
|
|
1045
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1046
|
+
super(
|
|
1047
|
+
[
|
|
1048
|
+
"hexpireat",
|
|
1049
|
+
key,
|
|
1050
|
+
timestamp,
|
|
1051
|
+
...option ? [option] : [],
|
|
1052
|
+
"FIELDS",
|
|
1053
|
+
fieldArray.length,
|
|
1054
|
+
...fieldArray
|
|
1055
|
+
],
|
|
1056
|
+
opts
|
|
1057
|
+
);
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
// pkg/commands/hexpiretime.ts
|
|
1062
|
+
var HExpireTimeCommand = class extends Command {
|
|
1063
|
+
constructor(cmd, opts) {
|
|
1064
|
+
const [key, fields] = cmd;
|
|
1065
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1066
|
+
super(["hexpiretime", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
// pkg/commands/hpersist.ts
|
|
1071
|
+
var HPersistCommand = class extends Command {
|
|
1072
|
+
constructor(cmd, opts) {
|
|
1073
|
+
const [key, fields] = cmd;
|
|
1074
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1075
|
+
super(["hpersist", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
|
|
1079
|
+
// pkg/commands/hpexpire.ts
|
|
1080
|
+
var HPExpireCommand = class extends Command {
|
|
1081
|
+
constructor(cmd, opts) {
|
|
1082
|
+
const [key, fields, milliseconds, option] = cmd;
|
|
1083
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1084
|
+
super(
|
|
1085
|
+
[
|
|
1086
|
+
"hpexpire",
|
|
1087
|
+
key,
|
|
1088
|
+
milliseconds,
|
|
1089
|
+
...option ? [option] : [],
|
|
1090
|
+
"FIELDS",
|
|
1091
|
+
fieldArray.length,
|
|
1092
|
+
...fieldArray
|
|
1093
|
+
],
|
|
1094
|
+
opts
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
|
|
1099
|
+
// pkg/commands/hpexpireat.ts
|
|
1100
|
+
var HPExpireAtCommand = class extends Command {
|
|
1101
|
+
constructor(cmd, opts) {
|
|
1102
|
+
const [key, fields, timestamp, option] = cmd;
|
|
1103
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1104
|
+
super(
|
|
1105
|
+
[
|
|
1106
|
+
"hpexpireat",
|
|
1107
|
+
key,
|
|
1108
|
+
timestamp,
|
|
1109
|
+
...option ? [option] : [],
|
|
1110
|
+
"FIELDS",
|
|
1111
|
+
fieldArray.length,
|
|
1112
|
+
...fieldArray
|
|
1113
|
+
],
|
|
1114
|
+
opts
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
// pkg/commands/hpexpiretime.ts
|
|
1120
|
+
var HPExpireTimeCommand = class extends Command {
|
|
1121
|
+
constructor(cmd, opts) {
|
|
1122
|
+
const [key, fields] = cmd;
|
|
1123
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1124
|
+
super(["hpexpiretime", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
// pkg/commands/hpttl.ts
|
|
1129
|
+
var HPTtlCommand = class extends Command {
|
|
1130
|
+
constructor(cmd, opts) {
|
|
1131
|
+
const [key, fields] = cmd;
|
|
1132
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1133
|
+
super(["hpttl", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
|
|
862
1137
|
// pkg/commands/hget.ts
|
|
863
1138
|
var HGetCommand = class extends Command {
|
|
864
1139
|
constructor(cmd, opts) {
|
|
@@ -867,14 +1142,14 @@ var HGetCommand = class extends Command {
|
|
|
867
1142
|
};
|
|
868
1143
|
|
|
869
1144
|
// pkg/commands/hgetall.ts
|
|
870
|
-
function
|
|
1145
|
+
function deserialize3(result) {
|
|
871
1146
|
if (result.length === 0) {
|
|
872
1147
|
return null;
|
|
873
1148
|
}
|
|
874
1149
|
const obj = {};
|
|
875
|
-
|
|
876
|
-
const key = result
|
|
877
|
-
const value = result
|
|
1150
|
+
for (let i = 0; i < result.length; i += 2) {
|
|
1151
|
+
const key = result[i];
|
|
1152
|
+
const value = result[i + 1];
|
|
878
1153
|
try {
|
|
879
1154
|
const valueIsNumberAndNotSafeInteger = !Number.isNaN(Number(value)) && !Number.isSafeInteger(Number(value));
|
|
880
1155
|
obj[key] = valueIsNumberAndNotSafeInteger ? value : JSON.parse(value);
|
|
@@ -887,7 +1162,7 @@ function deserialize(result) {
|
|
|
887
1162
|
var HGetAllCommand = class extends Command {
|
|
888
1163
|
constructor(cmd, opts) {
|
|
889
1164
|
super(["hgetall", ...cmd], {
|
|
890
|
-
deserialize: (result) =>
|
|
1165
|
+
deserialize: (result) => deserialize3(result),
|
|
891
1166
|
...opts
|
|
892
1167
|
});
|
|
893
1168
|
}
|
|
@@ -922,7 +1197,7 @@ var HLenCommand = class extends Command {
|
|
|
922
1197
|
};
|
|
923
1198
|
|
|
924
1199
|
// pkg/commands/hmget.ts
|
|
925
|
-
function
|
|
1200
|
+
function deserialize4(fields, result) {
|
|
926
1201
|
if (result.every((field) => field === null)) {
|
|
927
1202
|
return null;
|
|
928
1203
|
}
|
|
@@ -939,7 +1214,7 @@ function deserialize2(fields, result) {
|
|
|
939
1214
|
var HMGetCommand = class extends Command {
|
|
940
1215
|
constructor([key, ...fields], opts) {
|
|
941
1216
|
super(["hmget", key, ...fields], {
|
|
942
|
-
deserialize: (result) =>
|
|
1217
|
+
deserialize: (result) => deserialize4(fields, result),
|
|
943
1218
|
...opts
|
|
944
1219
|
});
|
|
945
1220
|
}
|
|
@@ -953,14 +1228,14 @@ var HMSetCommand = class extends Command {
|
|
|
953
1228
|
};
|
|
954
1229
|
|
|
955
1230
|
// pkg/commands/hrandfield.ts
|
|
956
|
-
function
|
|
1231
|
+
function deserialize5(result) {
|
|
957
1232
|
if (result.length === 0) {
|
|
958
1233
|
return null;
|
|
959
1234
|
}
|
|
960
1235
|
const obj = {};
|
|
961
|
-
|
|
962
|
-
const key = result
|
|
963
|
-
const value = result
|
|
1236
|
+
for (let i = 0; i < result.length; i += 2) {
|
|
1237
|
+
const key = result[i];
|
|
1238
|
+
const value = result[i + 1];
|
|
964
1239
|
try {
|
|
965
1240
|
obj[key] = JSON.parse(value);
|
|
966
1241
|
} catch {
|
|
@@ -980,7 +1255,7 @@ var HRandFieldCommand = class extends Command {
|
|
|
980
1255
|
}
|
|
981
1256
|
super(command, {
|
|
982
1257
|
// @ts-expect-error to silence compiler
|
|
983
|
-
deserialize: cmd[2] ? (result) =>
|
|
1258
|
+
deserialize: cmd[2] ? (result) => deserialize5(result) : opts?.deserialize,
|
|
984
1259
|
...opts
|
|
985
1260
|
});
|
|
986
1261
|
}
|
|
@@ -1024,6 +1299,15 @@ var HStrLenCommand = class extends Command {
|
|
|
1024
1299
|
}
|
|
1025
1300
|
};
|
|
1026
1301
|
|
|
1302
|
+
// pkg/commands/httl.ts
|
|
1303
|
+
var HTtlCommand = class extends Command {
|
|
1304
|
+
constructor(cmd, opts) {
|
|
1305
|
+
const [key, fields] = cmd;
|
|
1306
|
+
const fieldArray = Array.isArray(fields) ? fields : [fields];
|
|
1307
|
+
super(["httl", key, "FIELDS", fieldArray.length, ...fieldArray], opts);
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1027
1311
|
// pkg/commands/hvals.ts
|
|
1028
1312
|
var HValsCommand = class extends Command {
|
|
1029
1313
|
constructor(cmd, opts) {
|
|
@@ -1143,6 +1427,14 @@ var JsonGetCommand = class extends Command {
|
|
|
1143
1427
|
}
|
|
1144
1428
|
};
|
|
1145
1429
|
|
|
1430
|
+
// pkg/commands/json_merge.ts
|
|
1431
|
+
var JsonMergeCommand = class extends Command {
|
|
1432
|
+
constructor(cmd, opts) {
|
|
1433
|
+
const command = ["JSON.MERGE", ...cmd];
|
|
1434
|
+
super(command, opts);
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
|
|
1146
1438
|
// pkg/commands/json_mget.ts
|
|
1147
1439
|
var JsonMGetCommand = class extends Command {
|
|
1148
1440
|
constructor(cmd, opts) {
|
|
@@ -1503,11 +1795,14 @@ var ScanCommand = class extends Command {
|
|
|
1503
1795
|
if (typeof opts?.count === "number") {
|
|
1504
1796
|
command.push("count", opts.count);
|
|
1505
1797
|
}
|
|
1506
|
-
if (opts
|
|
1798
|
+
if (opts && "withType" in opts && opts.withType === true) {
|
|
1799
|
+
command.push("withtype");
|
|
1800
|
+
} else if (opts && "type" in opts && opts.type && opts.type.length > 0) {
|
|
1507
1801
|
command.push("type", opts.type);
|
|
1508
1802
|
}
|
|
1509
1803
|
super(command, {
|
|
1510
|
-
|
|
1804
|
+
// @ts-expect-error ignore types here
|
|
1805
|
+
deserialize: opts?.withType ? deserializeScanWithTypesResponse : deserializeScanResponse,
|
|
1511
1806
|
...cmdOpts
|
|
1512
1807
|
});
|
|
1513
1808
|
}
|
|
@@ -1930,18 +2225,18 @@ var XPendingCommand = class extends Command {
|
|
|
1930
2225
|
};
|
|
1931
2226
|
|
|
1932
2227
|
// pkg/commands/xrange.ts
|
|
1933
|
-
function
|
|
2228
|
+
function deserialize6(result) {
|
|
1934
2229
|
const obj = {};
|
|
1935
2230
|
for (const e of result) {
|
|
1936
|
-
|
|
1937
|
-
const streamId = e
|
|
1938
|
-
const entries = e
|
|
2231
|
+
for (let i = 0; i < e.length; i += 2) {
|
|
2232
|
+
const streamId = e[i];
|
|
2233
|
+
const entries = e[i + 1];
|
|
1939
2234
|
if (!(streamId in obj)) {
|
|
1940
2235
|
obj[streamId] = {};
|
|
1941
2236
|
}
|
|
1942
|
-
|
|
1943
|
-
const field = entries
|
|
1944
|
-
const value = entries
|
|
2237
|
+
for (let j = 0; j < entries.length; j += 2) {
|
|
2238
|
+
const field = entries[j];
|
|
2239
|
+
const value = entries[j + 1];
|
|
1945
2240
|
try {
|
|
1946
2241
|
obj[streamId][field] = JSON.parse(value);
|
|
1947
2242
|
} catch {
|
|
@@ -1959,7 +2254,7 @@ var XRangeCommand = class extends Command {
|
|
|
1959
2254
|
command.push("COUNT", count);
|
|
1960
2255
|
}
|
|
1961
2256
|
super(command, {
|
|
1962
|
-
deserialize: (result) =>
|
|
2257
|
+
deserialize: (result) => deserialize6(result),
|
|
1963
2258
|
...opts
|
|
1964
2259
|
});
|
|
1965
2260
|
}
|
|
@@ -2022,23 +2317,23 @@ var XRevRangeCommand = class extends Command {
|
|
|
2022
2317
|
command.push("COUNT", count);
|
|
2023
2318
|
}
|
|
2024
2319
|
super(command, {
|
|
2025
|
-
deserialize: (result) =>
|
|
2320
|
+
deserialize: (result) => deserialize7(result),
|
|
2026
2321
|
...opts
|
|
2027
2322
|
});
|
|
2028
2323
|
}
|
|
2029
2324
|
};
|
|
2030
|
-
function
|
|
2325
|
+
function deserialize7(result) {
|
|
2031
2326
|
const obj = {};
|
|
2032
2327
|
for (const e of result) {
|
|
2033
|
-
|
|
2034
|
-
const streamId = e
|
|
2035
|
-
const entries = e
|
|
2328
|
+
for (let i = 0; i < e.length; i += 2) {
|
|
2329
|
+
const streamId = e[i];
|
|
2330
|
+
const entries = e[i + 1];
|
|
2036
2331
|
if (!(streamId in obj)) {
|
|
2037
2332
|
obj[streamId] = {};
|
|
2038
2333
|
}
|
|
2039
|
-
|
|
2040
|
-
const field = entries
|
|
2041
|
-
const value = entries
|
|
2334
|
+
for (let j = 0; j < entries.length; j += 2) {
|
|
2335
|
+
const field = entries[j];
|
|
2336
|
+
const value = entries[j + 1];
|
|
2042
2337
|
try {
|
|
2043
2338
|
obj[streamId][field] = JSON.parse(value);
|
|
2044
2339
|
} catch {
|
|
@@ -2323,11 +2618,13 @@ var Subscriber = class extends EventTarget {
|
|
|
2323
2618
|
subscriptions;
|
|
2324
2619
|
client;
|
|
2325
2620
|
listeners;
|
|
2326
|
-
|
|
2621
|
+
opts;
|
|
2622
|
+
constructor(client, channels, isPattern = false, opts) {
|
|
2327
2623
|
super();
|
|
2328
2624
|
this.client = client;
|
|
2329
2625
|
this.subscriptions = /* @__PURE__ */ new Map();
|
|
2330
2626
|
this.listeners = /* @__PURE__ */ new Map();
|
|
2627
|
+
this.opts = opts;
|
|
2331
2628
|
for (const channel of channels) {
|
|
2332
2629
|
if (isPattern) {
|
|
2333
2630
|
this.subscribeToPattern(channel);
|
|
@@ -2386,10 +2683,9 @@ var Subscriber = class extends EventTarget {
|
|
|
2386
2683
|
const channel = messageData.slice(secondCommaIndex + 1, thirdCommaIndex);
|
|
2387
2684
|
const messageStr = messageData.slice(thirdCommaIndex + 1);
|
|
2388
2685
|
try {
|
|
2389
|
-
const message = JSON.parse(messageStr);
|
|
2390
|
-
this.dispatchToListeners("pmessage", message);
|
|
2391
|
-
this.dispatchToListeners(`
|
|
2392
|
-
this.dispatchToListeners(`pmessage:${pattern}`, { channel, message });
|
|
2686
|
+
const message = this.opts?.automaticDeserialization === false ? messageStr : JSON.parse(messageStr);
|
|
2687
|
+
this.dispatchToListeners("pmessage", { pattern, channel, message });
|
|
2688
|
+
this.dispatchToListeners(`pmessage:${pattern}`, { pattern, channel, message });
|
|
2393
2689
|
} catch (error) {
|
|
2394
2690
|
this.dispatchToListeners("error", new Error(`Failed to parse message: ${error}`));
|
|
2395
2691
|
}
|
|
@@ -2397,10 +2693,14 @@ var Subscriber = class extends EventTarget {
|
|
|
2397
2693
|
const channel = messageData.slice(firstCommaIndex + 1, secondCommaIndex);
|
|
2398
2694
|
const messageStr = messageData.slice(secondCommaIndex + 1);
|
|
2399
2695
|
try {
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2696
|
+
if (type === "subscribe" || type === "psubscribe" || type === "unsubscribe" || type === "punsubscribe") {
|
|
2697
|
+
const count = Number.parseInt(messageStr);
|
|
2698
|
+
this.dispatchToListeners(type, count);
|
|
2699
|
+
} else {
|
|
2700
|
+
const message = this.opts?.automaticDeserialization === false ? messageStr : parseWithTryCatch(messageStr);
|
|
2701
|
+
this.dispatchToListeners(type, { channel, message });
|
|
2702
|
+
this.dispatchToListeners(`${type}:${channel}`, { channel, message });
|
|
2703
|
+
}
|
|
2404
2704
|
} catch (error) {
|
|
2405
2705
|
this.dispatchToListeners("error", new Error(`Failed to parse message: ${error}`));
|
|
2406
2706
|
}
|
|
@@ -2470,6 +2770,13 @@ var SubscribeCommand = class extends Command {
|
|
|
2470
2770
|
});
|
|
2471
2771
|
}
|
|
2472
2772
|
};
|
|
2773
|
+
var parseWithTryCatch = (str) => {
|
|
2774
|
+
try {
|
|
2775
|
+
return JSON.parse(str);
|
|
2776
|
+
} catch {
|
|
2777
|
+
return str;
|
|
2778
|
+
}
|
|
2779
|
+
};
|
|
2473
2780
|
|
|
2474
2781
|
// pkg/commands/zdiffstore.ts
|
|
2475
2782
|
var ZDiffStoreCommand = class extends Command {
|
|
@@ -2611,10 +2918,18 @@ var Pipeline = class {
|
|
|
2611
2918
|
* @see https://redis.io/commands/echo
|
|
2612
2919
|
*/
|
|
2613
2920
|
echo = (...args) => this.chain(new EchoCommand(args, this.commandOptions));
|
|
2921
|
+
/**
|
|
2922
|
+
* @see https://redis.io/commands/eval_ro
|
|
2923
|
+
*/
|
|
2924
|
+
evalRo = (...args) => this.chain(new EvalROCommand(args, this.commandOptions));
|
|
2614
2925
|
/**
|
|
2615
2926
|
* @see https://redis.io/commands/eval
|
|
2616
2927
|
*/
|
|
2617
2928
|
eval = (...args) => this.chain(new EvalCommand(args, this.commandOptions));
|
|
2929
|
+
/**
|
|
2930
|
+
* @see https://redis.io/commands/evalsha_ro
|
|
2931
|
+
*/
|
|
2932
|
+
evalshaRo = (...args) => this.chain(new EvalshaROCommand(args, this.commandOptions));
|
|
2618
2933
|
/**
|
|
2619
2934
|
* @see https://redis.io/commands/evalsha
|
|
2620
2935
|
*/
|
|
@@ -2695,6 +3010,42 @@ var Pipeline = class {
|
|
|
2695
3010
|
* @see https://redis.io/commands/hexists
|
|
2696
3011
|
*/
|
|
2697
3012
|
hexists = (...args) => this.chain(new HExistsCommand(args, this.commandOptions));
|
|
3013
|
+
/**
|
|
3014
|
+
* @see https://redis.io/commands/hexpire
|
|
3015
|
+
*/
|
|
3016
|
+
hexpire = (...args) => this.chain(new HExpireCommand(args, this.commandOptions));
|
|
3017
|
+
/**
|
|
3018
|
+
* @see https://redis.io/commands/hexpireat
|
|
3019
|
+
*/
|
|
3020
|
+
hexpireat = (...args) => this.chain(new HExpireAtCommand(args, this.commandOptions));
|
|
3021
|
+
/**
|
|
3022
|
+
* @see https://redis.io/commands/hexpiretime
|
|
3023
|
+
*/
|
|
3024
|
+
hexpiretime = (...args) => this.chain(new HExpireTimeCommand(args, this.commandOptions));
|
|
3025
|
+
/**
|
|
3026
|
+
* @see https://redis.io/commands/httl
|
|
3027
|
+
*/
|
|
3028
|
+
httl = (...args) => this.chain(new HTtlCommand(args, this.commandOptions));
|
|
3029
|
+
/**
|
|
3030
|
+
* @see https://redis.io/commands/hpexpire
|
|
3031
|
+
*/
|
|
3032
|
+
hpexpire = (...args) => this.chain(new HPExpireCommand(args, this.commandOptions));
|
|
3033
|
+
/**
|
|
3034
|
+
* @see https://redis.io/commands/hpexpireat
|
|
3035
|
+
*/
|
|
3036
|
+
hpexpireat = (...args) => this.chain(new HPExpireAtCommand(args, this.commandOptions));
|
|
3037
|
+
/**
|
|
3038
|
+
* @see https://redis.io/commands/hpexpiretime
|
|
3039
|
+
*/
|
|
3040
|
+
hpexpiretime = (...args) => this.chain(new HPExpireTimeCommand(args, this.commandOptions));
|
|
3041
|
+
/**
|
|
3042
|
+
* @see https://redis.io/commands/hpttl
|
|
3043
|
+
*/
|
|
3044
|
+
hpttl = (...args) => this.chain(new HPTtlCommand(args, this.commandOptions));
|
|
3045
|
+
/**
|
|
3046
|
+
* @see https://redis.io/commands/hpersist
|
|
3047
|
+
*/
|
|
3048
|
+
hpersist = (...args) => this.chain(new HPersistCommand(args, this.commandOptions));
|
|
2698
3049
|
/**
|
|
2699
3050
|
* @see https://redis.io/commands/hget
|
|
2700
3051
|
*/
|
|
@@ -3212,6 +3563,10 @@ var Pipeline = class {
|
|
|
3212
3563
|
* @see https://redis.io/commands/json.get
|
|
3213
3564
|
*/
|
|
3214
3565
|
get: (...args) => this.chain(new JsonGetCommand(args, this.commandOptions)),
|
|
3566
|
+
/**
|
|
3567
|
+
* @see https://redis.io/commands/json.merge
|
|
3568
|
+
*/
|
|
3569
|
+
merge: (...args) => this.chain(new JsonMergeCommand(args, this.commandOptions)),
|
|
3215
3570
|
/**
|
|
3216
3571
|
* @see https://redis.io/commands/json.mget
|
|
3217
3572
|
*/
|
|
@@ -3262,30 +3617,78 @@ var Pipeline = class {
|
|
|
3262
3617
|
type: (...args) => this.chain(new JsonTypeCommand(args, this.commandOptions))
|
|
3263
3618
|
};
|
|
3264
3619
|
}
|
|
3620
|
+
get functions() {
|
|
3621
|
+
return {
|
|
3622
|
+
/**
|
|
3623
|
+
* @see https://redis.io/docs/latest/commands/function-load/
|
|
3624
|
+
*/
|
|
3625
|
+
load: (...args) => this.chain(new FunctionLoadCommand(args, this.commandOptions)),
|
|
3626
|
+
/**
|
|
3627
|
+
* @see https://redis.io/docs/latest/commands/function-list/
|
|
3628
|
+
*/
|
|
3629
|
+
list: (...args) => this.chain(new FunctionListCommand(args, this.commandOptions)),
|
|
3630
|
+
/**
|
|
3631
|
+
* @see https://redis.io/docs/latest/commands/function-delete/
|
|
3632
|
+
*/
|
|
3633
|
+
delete: (...args) => this.chain(new FunctionDeleteCommand(args, this.commandOptions)),
|
|
3634
|
+
/**
|
|
3635
|
+
* @see https://redis.io/docs/latest/commands/function-flush/
|
|
3636
|
+
*/
|
|
3637
|
+
flush: () => this.chain(new FunctionFlushCommand(this.commandOptions)),
|
|
3638
|
+
/**
|
|
3639
|
+
* @see https://redis.io/docs/latest/commands/function-stats/
|
|
3640
|
+
*/
|
|
3641
|
+
stats: () => this.chain(new FunctionStatsCommand(this.commandOptions)),
|
|
3642
|
+
/**
|
|
3643
|
+
* @see https://redis.io/docs/latest/commands/fcall/
|
|
3644
|
+
*/
|
|
3645
|
+
call: (...args) => this.chain(new FCallCommand(args, this.commandOptions)),
|
|
3646
|
+
/**
|
|
3647
|
+
* @see https://redis.io/docs/latest/commands/fcall_ro/
|
|
3648
|
+
*/
|
|
3649
|
+
callRo: (...args) => this.chain(new FCallRoCommand(args, this.commandOptions))
|
|
3650
|
+
};
|
|
3651
|
+
}
|
|
3265
3652
|
};
|
|
3266
3653
|
|
|
3267
3654
|
// pkg/script.ts
|
|
3268
|
-
var
|
|
3269
|
-
var import_sha1 = __toESM(require("crypto-js/sha1.js"));
|
|
3655
|
+
var import_uncrypto = require("uncrypto");
|
|
3270
3656
|
var Script = class {
|
|
3271
3657
|
script;
|
|
3658
|
+
/**
|
|
3659
|
+
* @deprecated This property is initialized to an empty string and will be set in the init method
|
|
3660
|
+
* asynchronously. Do not use this property immidiately after the constructor.
|
|
3661
|
+
*
|
|
3662
|
+
* This property is only exposed for backwards compatibility and will be removed in the
|
|
3663
|
+
* future major release.
|
|
3664
|
+
*/
|
|
3272
3665
|
sha1;
|
|
3273
3666
|
redis;
|
|
3274
3667
|
constructor(redis, script) {
|
|
3275
3668
|
this.redis = redis;
|
|
3276
|
-
this.sha1 = this.digest(script);
|
|
3277
3669
|
this.script = script;
|
|
3670
|
+
this.sha1 = "";
|
|
3671
|
+
void this.init(script);
|
|
3672
|
+
}
|
|
3673
|
+
/**
|
|
3674
|
+
* Initialize the script by computing its SHA-1 hash.
|
|
3675
|
+
*/
|
|
3676
|
+
async init(script) {
|
|
3677
|
+
if (this.sha1) return;
|
|
3678
|
+
this.sha1 = await this.digest(script);
|
|
3278
3679
|
}
|
|
3279
3680
|
/**
|
|
3280
3681
|
* Send an `EVAL` command to redis.
|
|
3281
3682
|
*/
|
|
3282
3683
|
async eval(keys, args) {
|
|
3684
|
+
await this.init(this.script);
|
|
3283
3685
|
return await this.redis.eval(this.script, keys, args);
|
|
3284
3686
|
}
|
|
3285
3687
|
/**
|
|
3286
3688
|
* Calculates the sha1 hash of the script and then calls `EVALSHA`.
|
|
3287
3689
|
*/
|
|
3288
3690
|
async evalsha(keys, args) {
|
|
3691
|
+
await this.init(this.script);
|
|
3289
3692
|
return await this.redis.evalsha(this.sha1, keys, args);
|
|
3290
3693
|
}
|
|
3291
3694
|
/**
|
|
@@ -3295,6 +3698,7 @@ var Script = class {
|
|
|
3295
3698
|
* Following calls will be able to use the cached script
|
|
3296
3699
|
*/
|
|
3297
3700
|
async exec(keys, args) {
|
|
3701
|
+
await this.init(this.script);
|
|
3298
3702
|
const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (error) => {
|
|
3299
3703
|
if (error instanceof Error && error.message.toLowerCase().includes("noscript")) {
|
|
3300
3704
|
return await this.redis.eval(this.script, keys, args);
|
|
@@ -3306,8 +3710,75 @@ var Script = class {
|
|
|
3306
3710
|
/**
|
|
3307
3711
|
* Compute the sha1 hash of the script and return its hex representation.
|
|
3308
3712
|
*/
|
|
3309
|
-
digest(s) {
|
|
3310
|
-
|
|
3713
|
+
async digest(s) {
|
|
3714
|
+
const data = new TextEncoder().encode(s);
|
|
3715
|
+
const hashBuffer = await import_uncrypto.subtle.digest("SHA-1", data);
|
|
3716
|
+
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3717
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3718
|
+
}
|
|
3719
|
+
};
|
|
3720
|
+
|
|
3721
|
+
// pkg/scriptRo.ts
|
|
3722
|
+
var import_uncrypto2 = require("uncrypto");
|
|
3723
|
+
var ScriptRO = class {
|
|
3724
|
+
script;
|
|
3725
|
+
/**
|
|
3726
|
+
* @deprecated This property is initialized to an empty string and will be set in the init method
|
|
3727
|
+
* asynchronously. Do not use this property immidiately after the constructor.
|
|
3728
|
+
*
|
|
3729
|
+
* This property is only exposed for backwards compatibility and will be removed in the
|
|
3730
|
+
* future major release.
|
|
3731
|
+
*/
|
|
3732
|
+
sha1;
|
|
3733
|
+
redis;
|
|
3734
|
+
constructor(redis, script) {
|
|
3735
|
+
this.redis = redis;
|
|
3736
|
+
this.sha1 = "";
|
|
3737
|
+
this.script = script;
|
|
3738
|
+
void this.init(script);
|
|
3739
|
+
}
|
|
3740
|
+
async init(script) {
|
|
3741
|
+
if (this.sha1) return;
|
|
3742
|
+
this.sha1 = await this.digest(script);
|
|
3743
|
+
}
|
|
3744
|
+
/**
|
|
3745
|
+
* Send an `EVAL_RO` command to redis.
|
|
3746
|
+
*/
|
|
3747
|
+
async evalRo(keys, args) {
|
|
3748
|
+
await this.init(this.script);
|
|
3749
|
+
return await this.redis.evalRo(this.script, keys, args);
|
|
3750
|
+
}
|
|
3751
|
+
/**
|
|
3752
|
+
* Calculates the sha1 hash of the script and then calls `EVALSHA_RO`.
|
|
3753
|
+
*/
|
|
3754
|
+
async evalshaRo(keys, args) {
|
|
3755
|
+
await this.init(this.script);
|
|
3756
|
+
return await this.redis.evalshaRo(this.sha1, keys, args);
|
|
3757
|
+
}
|
|
3758
|
+
/**
|
|
3759
|
+
* Optimistically try to run `EVALSHA_RO` first.
|
|
3760
|
+
* If the script is not loaded in redis, it will fall back and try again with `EVAL_RO`.
|
|
3761
|
+
*
|
|
3762
|
+
* Following calls will be able to use the cached script
|
|
3763
|
+
*/
|
|
3764
|
+
async exec(keys, args) {
|
|
3765
|
+
await this.init(this.script);
|
|
3766
|
+
const res = await this.redis.evalshaRo(this.sha1, keys, args).catch(async (error) => {
|
|
3767
|
+
if (error instanceof Error && error.message.toLowerCase().includes("noscript")) {
|
|
3768
|
+
return await this.redis.evalRo(this.script, keys, args);
|
|
3769
|
+
}
|
|
3770
|
+
throw error;
|
|
3771
|
+
});
|
|
3772
|
+
return res;
|
|
3773
|
+
}
|
|
3774
|
+
/**
|
|
3775
|
+
* Compute the sha1 hash of the script and return its hex representation.
|
|
3776
|
+
*/
|
|
3777
|
+
async digest(s) {
|
|
3778
|
+
const data = new TextEncoder().encode(s);
|
|
3779
|
+
const hashBuffer = await import_uncrypto2.subtle.digest("SHA-1", data);
|
|
3780
|
+
const hashArray = [...new Uint8Array(hashBuffer)];
|
|
3781
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
3311
3782
|
}
|
|
3312
3783
|
};
|
|
3313
3784
|
|
|
@@ -3385,6 +3856,10 @@ var Redis = class {
|
|
|
3385
3856
|
* @see https://redis.io/commands/json.get
|
|
3386
3857
|
*/
|
|
3387
3858
|
get: (...args) => new JsonGetCommand(args, this.opts).exec(this.client),
|
|
3859
|
+
/**
|
|
3860
|
+
* @see https://redis.io/commands/json.merge
|
|
3861
|
+
*/
|
|
3862
|
+
merge: (...args) => new JsonMergeCommand(args, this.opts).exec(this.client),
|
|
3388
3863
|
/**
|
|
3389
3864
|
* @see https://redis.io/commands/json.mget
|
|
3390
3865
|
*/
|
|
@@ -3435,6 +3910,40 @@ var Redis = class {
|
|
|
3435
3910
|
type: (...args) => new JsonTypeCommand(args, this.opts).exec(this.client)
|
|
3436
3911
|
};
|
|
3437
3912
|
}
|
|
3913
|
+
get functions() {
|
|
3914
|
+
return {
|
|
3915
|
+
/**
|
|
3916
|
+
* @see https://redis.io/docs/latest/commands/function-load/
|
|
3917
|
+
*/
|
|
3918
|
+
load: (...args) => new FunctionLoadCommand(args, this.opts).exec(this.client),
|
|
3919
|
+
/**
|
|
3920
|
+
* @see https://redis.io/docs/latest/commands/function-list/
|
|
3921
|
+
*/
|
|
3922
|
+
list: (...args) => new FunctionListCommand(args, this.opts).exec(this.client),
|
|
3923
|
+
/**
|
|
3924
|
+
* @see https://redis.io/docs/latest/commands/function-delete/
|
|
3925
|
+
*/
|
|
3926
|
+
delete: (...args) => new FunctionDeleteCommand(args, this.opts).exec(this.client),
|
|
3927
|
+
/**
|
|
3928
|
+
* @see https://redis.io/docs/latest/commands/function-flush/
|
|
3929
|
+
*/
|
|
3930
|
+
flush: () => new FunctionFlushCommand(this.opts).exec(this.client),
|
|
3931
|
+
/**
|
|
3932
|
+
* @see https://redis.io/docs/latest/commands/function-stats/
|
|
3933
|
+
*
|
|
3934
|
+
* Note: `running_script` field is not supported and therefore not included in the type.
|
|
3935
|
+
*/
|
|
3936
|
+
stats: () => new FunctionStatsCommand(this.opts).exec(this.client),
|
|
3937
|
+
/**
|
|
3938
|
+
* @see https://redis.io/docs/latest/commands/fcall/
|
|
3939
|
+
*/
|
|
3940
|
+
call: (...args) => new FCallCommand(args, this.opts).exec(this.client),
|
|
3941
|
+
/**
|
|
3942
|
+
* @see https://redis.io/docs/latest/commands/fcall_ro/
|
|
3943
|
+
*/
|
|
3944
|
+
callRo: (...args) => new FCallRoCommand(args, this.opts).exec(this.client)
|
|
3945
|
+
};
|
|
3946
|
+
}
|
|
3438
3947
|
/**
|
|
3439
3948
|
* Wrap a new middleware around the HTTP client.
|
|
3440
3949
|
*/
|
|
@@ -3454,8 +3963,36 @@ var Redis = class {
|
|
|
3454
3963
|
} catch {
|
|
3455
3964
|
}
|
|
3456
3965
|
};
|
|
3457
|
-
|
|
3458
|
-
|
|
3966
|
+
/**
|
|
3967
|
+
* Creates a new script.
|
|
3968
|
+
*
|
|
3969
|
+
* Scripts offer the ability to optimistically try to execute a script without having to send the
|
|
3970
|
+
* entire script to the server. If the script is loaded on the server, it tries again by sending
|
|
3971
|
+
* the entire script. Afterwards, the script is cached on the server.
|
|
3972
|
+
*
|
|
3973
|
+
* @param script - The script to create
|
|
3974
|
+
* @param opts - Optional options to pass to the script `{ readonly?: boolean }`
|
|
3975
|
+
* @returns A new script
|
|
3976
|
+
*
|
|
3977
|
+
* @example
|
|
3978
|
+
* ```ts
|
|
3979
|
+
* const redis = new Redis({...})
|
|
3980
|
+
*
|
|
3981
|
+
* const script = redis.createScript<string>("return ARGV[1];")
|
|
3982
|
+
* const arg1 = await script.eval([], ["Hello World"])
|
|
3983
|
+
* expect(arg1, "Hello World")
|
|
3984
|
+
* ```
|
|
3985
|
+
* @example
|
|
3986
|
+
* ```ts
|
|
3987
|
+
* const redis = new Redis({...})
|
|
3988
|
+
*
|
|
3989
|
+
* const script = redis.createScript<string>("return ARGV[1];", { readonly: true })
|
|
3990
|
+
* const arg1 = await script.evalRo([], ["Hello World"])
|
|
3991
|
+
* expect(arg1, "Hello World")
|
|
3992
|
+
* ```
|
|
3993
|
+
*/
|
|
3994
|
+
createScript(script, opts) {
|
|
3995
|
+
return opts?.readonly ? new ScriptRO(this, script) : new Script(this, script);
|
|
3459
3996
|
}
|
|
3460
3997
|
/**
|
|
3461
3998
|
* Create a new pipeline that allows you to send requests in bulk.
|
|
@@ -3542,10 +4079,18 @@ var Redis = class {
|
|
|
3542
4079
|
* @see https://redis.io/commands/echo
|
|
3543
4080
|
*/
|
|
3544
4081
|
echo = (...args) => new EchoCommand(args, this.opts).exec(this.client);
|
|
4082
|
+
/**
|
|
4083
|
+
* @see https://redis.io/commands/eval_ro
|
|
4084
|
+
*/
|
|
4085
|
+
evalRo = (...args) => new EvalROCommand(args, this.opts).exec(this.client);
|
|
3545
4086
|
/**
|
|
3546
4087
|
* @see https://redis.io/commands/eval
|
|
3547
4088
|
*/
|
|
3548
4089
|
eval = (...args) => new EvalCommand(args, this.opts).exec(this.client);
|
|
4090
|
+
/**
|
|
4091
|
+
* @see https://redis.io/commands/evalsha_ro
|
|
4092
|
+
*/
|
|
4093
|
+
evalshaRo = (...args) => new EvalshaROCommand(args, this.opts).exec(this.client);
|
|
3549
4094
|
/**
|
|
3550
4095
|
* @see https://redis.io/commands/evalsha
|
|
3551
4096
|
*/
|
|
@@ -3630,6 +4175,42 @@ var Redis = class {
|
|
|
3630
4175
|
* @see https://redis.io/commands/hexists
|
|
3631
4176
|
*/
|
|
3632
4177
|
hexists = (...args) => new HExistsCommand(args, this.opts).exec(this.client);
|
|
4178
|
+
/**
|
|
4179
|
+
* @see https://redis.io/commands/hexpire
|
|
4180
|
+
*/
|
|
4181
|
+
hexpire = (...args) => new HExpireCommand(args, this.opts).exec(this.client);
|
|
4182
|
+
/**
|
|
4183
|
+
* @see https://redis.io/commands/hexpireat
|
|
4184
|
+
*/
|
|
4185
|
+
hexpireat = (...args) => new HExpireAtCommand(args, this.opts).exec(this.client);
|
|
4186
|
+
/**
|
|
4187
|
+
* @see https://redis.io/commands/hexpiretime
|
|
4188
|
+
*/
|
|
4189
|
+
hexpiretime = (...args) => new HExpireTimeCommand(args, this.opts).exec(this.client);
|
|
4190
|
+
/**
|
|
4191
|
+
* @see https://redis.io/commands/httl
|
|
4192
|
+
*/
|
|
4193
|
+
httl = (...args) => new HTtlCommand(args, this.opts).exec(this.client);
|
|
4194
|
+
/**
|
|
4195
|
+
* @see https://redis.io/commands/hpexpire
|
|
4196
|
+
*/
|
|
4197
|
+
hpexpire = (...args) => new HPExpireCommand(args, this.opts).exec(this.client);
|
|
4198
|
+
/**
|
|
4199
|
+
* @see https://redis.io/commands/hpexpireat
|
|
4200
|
+
*/
|
|
4201
|
+
hpexpireat = (...args) => new HPExpireAtCommand(args, this.opts).exec(this.client);
|
|
4202
|
+
/**
|
|
4203
|
+
* @see https://redis.io/commands/hpexpiretime
|
|
4204
|
+
*/
|
|
4205
|
+
hpexpiretime = (...args) => new HPExpireTimeCommand(args, this.opts).exec(this.client);
|
|
4206
|
+
/**
|
|
4207
|
+
* @see https://redis.io/commands/hpttl
|
|
4208
|
+
*/
|
|
4209
|
+
hpttl = (...args) => new HPTtlCommand(args, this.opts).exec(this.client);
|
|
4210
|
+
/**
|
|
4211
|
+
* @see https://redis.io/commands/hpersist
|
|
4212
|
+
*/
|
|
4213
|
+
hpersist = (...args) => new HPersistCommand(args, this.opts).exec(this.client);
|
|
3633
4214
|
/**
|
|
3634
4215
|
* @see https://redis.io/commands/hget
|
|
3635
4216
|
*/
|
|
@@ -3798,9 +4379,12 @@ var Redis = class {
|
|
|
3798
4379
|
* @see https://redis.io/commands/psetex
|
|
3799
4380
|
*/
|
|
3800
4381
|
psetex = (key, ttl, value) => new PSetEXCommand([key, ttl, value], this.opts).exec(this.client);
|
|
4382
|
+
/**
|
|
4383
|
+
* @see https://redis.io/commands/psubscribe
|
|
4384
|
+
*/
|
|
3801
4385
|
psubscribe = (patterns) => {
|
|
3802
4386
|
const patternArray = Array.isArray(patterns) ? patterns : [patterns];
|
|
3803
|
-
return new Subscriber(this.client, patternArray, true);
|
|
4387
|
+
return new Subscriber(this.client, patternArray, true, this.opts);
|
|
3804
4388
|
};
|
|
3805
4389
|
/**
|
|
3806
4390
|
* @see https://redis.io/commands/pttl
|
|
@@ -3838,10 +4422,9 @@ var Redis = class {
|
|
|
3838
4422
|
* @see https://redis.io/commands/sadd
|
|
3839
4423
|
*/
|
|
3840
4424
|
sadd = (key, member, ...members) => new SAddCommand([key, member, ...members], this.opts).exec(this.client);
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
scan = (...args) => new ScanCommand(args, this.opts).exec(this.client);
|
|
4425
|
+
scan(cursor, opts) {
|
|
4426
|
+
return new ScanCommand([cursor, opts], this.opts).exec(this.client);
|
|
4427
|
+
}
|
|
3845
4428
|
/**
|
|
3846
4429
|
* @see https://redis.io/commands/scard
|
|
3847
4430
|
*/
|
|
@@ -3935,7 +4518,7 @@ var Redis = class {
|
|
|
3935
4518
|
*/
|
|
3936
4519
|
subscribe = (channels) => {
|
|
3937
4520
|
const channelArray = Array.isArray(channels) ? channels : [channels];
|
|
3938
|
-
return new Subscriber(this.client, channelArray);
|
|
4521
|
+
return new Subscriber(this.client, channelArray, false, this.opts);
|
|
3939
4522
|
};
|
|
3940
4523
|
/**
|
|
3941
4524
|
* @see https://redis.io/commands/sunion
|
|
@@ -4176,18 +4759,20 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4176
4759
|
keepAlive: configOrRequester.keepAlive,
|
|
4177
4760
|
readYourWrites: configOrRequester.readYourWrites
|
|
4178
4761
|
});
|
|
4762
|
+
const safeEnv = typeof process === "object" && process && typeof process.env === "object" && process.env ? process.env : {};
|
|
4179
4763
|
super(client, {
|
|
4180
4764
|
automaticDeserialization: configOrRequester.automaticDeserialization,
|
|
4181
|
-
enableTelemetry: !
|
|
4765
|
+
enableTelemetry: configOrRequester.enableTelemetry ?? !safeEnv.UPSTASH_DISABLE_TELEMETRY,
|
|
4182
4766
|
latencyLogging: configOrRequester.latencyLogging,
|
|
4183
4767
|
enableAutoPipelining: configOrRequester.enableAutoPipelining
|
|
4184
4768
|
});
|
|
4769
|
+
const nodeVersion = typeof process === "object" && process ? process.version : void 0;
|
|
4185
4770
|
this.addTelemetry({
|
|
4186
4771
|
runtime: (
|
|
4187
4772
|
// @ts-expect-error to silence compiler
|
|
4188
|
-
typeof EdgeRuntime === "string" ? "edge-light" : `node@${
|
|
4773
|
+
typeof EdgeRuntime === "string" ? "edge-light" : nodeVersion ? `node@${nodeVersion}` : "unknown"
|
|
4189
4774
|
),
|
|
4190
|
-
platform:
|
|
4775
|
+
platform: safeEnv.UPSTASH_CONSOLE ? "console" : safeEnv.VERCEL ? "vercel" : safeEnv.AWS_REGION ? "aws" : "unknown",
|
|
4191
4776
|
sdk: `@upstash/redis@${VERSION}`
|
|
4192
4777
|
});
|
|
4193
4778
|
if (this.enableAutoPipelining) {
|
|
@@ -4200,11 +4785,15 @@ var Redis2 = class _Redis extends Redis {
|
|
|
4200
4785
|
* Use this to automatically load connection secrets from your environment
|
|
4201
4786
|
* variables. For instance when using the Vercel integration.
|
|
4202
4787
|
*
|
|
4203
|
-
* This tries to load
|
|
4204
|
-
*
|
|
4788
|
+
* This tries to load connection details from your environment using `process.env`:
|
|
4789
|
+
* - URL: `UPSTASH_REDIS_REST_URL` or fallback to `KV_REST_API_URL`
|
|
4790
|
+
* - Token: `UPSTASH_REDIS_REST_TOKEN` or fallback to `KV_REST_API_TOKEN`
|
|
4791
|
+
*
|
|
4792
|
+
* The fallback variables provide compatibility with Vercel KV and other platforms
|
|
4793
|
+
* that may use different naming conventions.
|
|
4205
4794
|
*/
|
|
4206
4795
|
static fromEnv(config) {
|
|
4207
|
-
if (process.env
|
|
4796
|
+
if (typeof process !== "object" || !process || typeof process.env !== "object" || !process.env) {
|
|
4208
4797
|
throw new TypeError(
|
|
4209
4798
|
'[Upstash Redis] Unable to get environment variables, `process.env` is undefined. If you are deploying to cloudflare, please import from "@upstash/redis/cloudflare" instead'
|
|
4210
4799
|
);
|