@upstash/redis 0.0.0-ci.c37cc01e → 0.0.0-ci.c586e271-20221116

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 (56) hide show
  1. package/README.md +0 -21
  2. package/esm/deps/deno.land/x/base64@v0.2.1/base.js +100 -0
  3. package/esm/deps/deno.land/x/base64@v0.2.1/base64url.js +9 -0
  4. package/esm/deps/deno.land/x/sha1@v1.0.3/deps.js +1 -0
  5. package/esm/deps/deno.land/x/sha1@v1.0.3/mod.js +191 -0
  6. package/esm/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +50 -0
  7. package/esm/pkg/commands/getdel.js +9 -0
  8. package/esm/pkg/commands/mod.js +1 -0
  9. package/esm/pkg/commands/scan.js +3 -0
  10. package/esm/pkg/commands/set.js +16 -4
  11. package/esm/pkg/commands/zmscore.js +10 -0
  12. package/esm/pkg/http.js +73 -2
  13. package/esm/pkg/pipeline.js +33 -6
  14. package/esm/pkg/redis.js +48 -2
  15. package/esm/pkg/script.js +77 -0
  16. package/esm/platforms/cloudflare.js +1 -0
  17. package/esm/platforms/fastly.js +1 -0
  18. package/esm/platforms/node_with_fetch.js +2 -1
  19. package/esm/platforms/nodejs.js +2 -1
  20. package/package.json +1 -39
  21. package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
  22. package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
  23. package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
  24. package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
  25. package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
  26. package/script/pkg/commands/getdel.js +13 -0
  27. package/script/pkg/commands/mod.js +1 -0
  28. package/script/pkg/commands/scan.js +3 -0
  29. package/script/pkg/commands/set.js +16 -4
  30. package/script/pkg/commands/zmscore.js +14 -0
  31. package/script/pkg/http.js +73 -2
  32. package/script/pkg/pipeline.js +32 -5
  33. package/script/pkg/redis.js +47 -1
  34. package/script/pkg/script.js +81 -0
  35. package/script/platforms/cloudflare.js +1 -0
  36. package/script/platforms/fastly.js +1 -0
  37. package/script/platforms/node_with_fetch.js +2 -1
  38. package/script/platforms/nodejs.js +2 -1
  39. package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
  40. package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
  41. package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
  42. package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
  43. package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
  44. package/types/pkg/commands/getdel.d.ts +7 -0
  45. package/types/pkg/commands/mod.d.ts +1 -0
  46. package/types/pkg/commands/scan.d.ts +1 -0
  47. package/types/pkg/commands/set.d.ts +31 -2
  48. package/types/pkg/commands/zmscore.d.ts +7 -0
  49. package/types/pkg/http.d.ts +35 -4
  50. package/types/pkg/pipeline.d.ts +16 -3
  51. package/types/pkg/redis.d.ts +21 -1
  52. package/types/pkg/script.d.ts +42 -0
  53. package/types/platforms/cloudflare.d.ts +3 -6
  54. package/types/platforms/fastly.d.ts +2 -6
  55. package/types/platforms/node_with_fetch.d.ts +2 -21
  56. package/types/platforms/nodejs.d.ts +3 -6
@@ -9,17 +9,29 @@ class SetCommand extends command_js_1.Command {
9
9
  constructor([key, value, opts], cmdOpts) {
10
10
  const command = ["set", key, value];
11
11
  if (opts) {
12
+ if ("nx" in opts && opts.nx) {
13
+ command.push("nx");
14
+ }
15
+ else if ("xx" in opts && opts.xx) {
16
+ command.push("xx");
17
+ }
18
+ if ("get" in opts && opts.get) {
19
+ command.push("get");
20
+ }
12
21
  if ("ex" in opts && typeof opts.ex === "number") {
13
22
  command.push("ex", opts.ex);
14
23
  }
15
24
  else if ("px" in opts && typeof opts.px === "number") {
16
25
  command.push("px", opts.px);
17
26
  }
18
- if ("nx" in opts && opts.nx) {
19
- command.push("nx");
27
+ else if ("exat" in opts && typeof opts.exat === "number") {
28
+ command.push("exat", opts.exat);
20
29
  }
21
- else if ("xx" in opts && opts.xx) {
22
- command.push("xx");
30
+ else if ("pxat" in opts && typeof opts.pxat === "number") {
31
+ command.push("pxat", opts.pxat);
32
+ }
33
+ else if ("keepTtl" in opts && opts.keepTtl) {
34
+ command.push("keepTtl", opts.keepTtl);
23
35
  }
24
36
  }
25
37
  super(command, cmdOpts);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZMScoreCommand = void 0;
4
+ const command_js_1 = require("./command.js");
5
+ /**
6
+ * @see https://redis.io/commands/zmscore
7
+ */
8
+ class ZMScoreCommand extends command_js_1.Command {
9
+ constructor(cmd, opts) {
10
+ const [key, members] = cmd;
11
+ super(["zmscore", key, ...members], opts);
12
+ }
13
+ }
14
+ exports.ZMScoreCommand = ZMScoreCommand;
@@ -28,9 +28,19 @@ class HttpClient {
28
28
  writable: true,
29
29
  value: void 0
30
30
  });
31
+ this.options = {
32
+ backend: config.options?.backend,
33
+ agent: config.agent,
34
+ responseEncoding: config.responseEncoding ?? "base64", // default to base64
35
+ };
31
36
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
32
- this.headers = { "Content-Type": "application/json", ...config.headers };
33
- this.options = { backend: config.options?.backend };
37
+ this.headers = {
38
+ "Content-Type": "application/json",
39
+ ...config.headers,
40
+ };
41
+ if (this.options.responseEncoding === "base64") {
42
+ this.headers["Upstash-Encoding"] = "base64";
43
+ }
34
44
  if (typeof config?.retry === "boolean" && config?.retry === false) {
35
45
  this.retry = {
36
46
  attempts: 1,
@@ -51,6 +61,7 @@ class HttpClient {
51
61
  headers: this.headers,
52
62
  body: JSON.stringify(req.body),
53
63
  keepalive: true,
64
+ agent: this.options?.agent,
54
65
  /**
55
66
  * Fastly specific
56
67
  */
@@ -75,7 +86,67 @@ class HttpClient {
75
86
  if (!res.ok) {
76
87
  throw new error_js_1.UpstashError(body.error);
77
88
  }
89
+ if (this.options?.responseEncoding === "base64") {
90
+ return Array.isArray(body) ? body.map(decode) : decode(body);
91
+ }
78
92
  return body;
79
93
  }
80
94
  }
81
95
  exports.HttpClient = HttpClient;
96
+ function base64decode(b64) {
97
+ let dec = "";
98
+ try {
99
+ /**
100
+ * Using only atob() is not enough because it doesn't work with unicode characters
101
+ */
102
+ const binString = atob(b64);
103
+ const size = binString.length;
104
+ const bytes = new Uint8Array(size);
105
+ for (let i = 0; i < size; i++) {
106
+ bytes[i] = binString.charCodeAt(i);
107
+ }
108
+ dec = new TextDecoder().decode(bytes);
109
+ }
110
+ catch {
111
+ dec = b64;
112
+ }
113
+ try {
114
+ return decodeURIComponent(dec);
115
+ }
116
+ catch {
117
+ return dec;
118
+ }
119
+ }
120
+ function decode(raw) {
121
+ let result = undefined;
122
+ switch (typeof raw.result) {
123
+ case "undefined":
124
+ return raw;
125
+ case "number": {
126
+ result = raw.result;
127
+ break;
128
+ }
129
+ case "object": {
130
+ if (Array.isArray(raw.result)) {
131
+ result = raw.result.map((v) => typeof v === "string"
132
+ ? base64decode(v)
133
+ : Array.isArray(v)
134
+ ? v.map(base64decode)
135
+ : v);
136
+ }
137
+ else {
138
+ // If it's not an array it must be null
139
+ // Apparently null is an object in javascript
140
+ result = null;
141
+ }
142
+ break;
143
+ }
144
+ case "string": {
145
+ result = raw.result === "OK" ? "OK" : base64decode(raw.result);
146
+ break;
147
+ }
148
+ default:
149
+ break;
150
+ }
151
+ return { result, error: raw.error };
152
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Pipeline = void 0;
4
4
  const mod_js_1 = require("./commands/mod.js");
5
5
  const error_js_1 = require("./error.js");
6
+ const zmscore_js_1 = require("./commands/zmscore.js");
6
7
  /**
7
8
  * Upstash REST API supports command pipelining to send multiple commands in
8
9
  * batch, instead of sending each command one by one and waiting for a response.
@@ -19,7 +20,7 @@ const error_js_1 = require("./error.js");
19
20
  * **Examples:**
20
21
  *
21
22
  * ```ts
22
- * const p = redis.pipeline()
23
+ * const p = redis.pipeline() // or redis.multi()
23
24
  * p.set("key","value")
24
25
  * p.get("key")
25
26
  * const res = await p.exec()
@@ -42,7 +43,7 @@ const error_js_1 = require("./error.js");
42
43
  * ```
43
44
  */
44
45
  class Pipeline {
45
- constructor(client, commandOptions) {
46
+ constructor(opts) {
46
47
  Object.defineProperty(this, "client", {
47
48
  enumerable: true,
48
49
  configurable: true,
@@ -61,6 +62,12 @@ class Pipeline {
61
62
  writable: true,
62
63
  value: void 0
63
64
  });
65
+ Object.defineProperty(this, "multiExec", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: void 0
70
+ });
64
71
  /**
65
72
  * Send the pipeline request to upstash.
66
73
  *
@@ -79,8 +86,9 @@ class Pipeline {
79
86
  if (this.commands.length === 0) {
80
87
  throw new Error("Pipeline is empty");
81
88
  }
89
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
82
90
  const res = (await this.client.request({
83
- path: ["pipeline"],
91
+ path,
84
92
  body: Object.values(this.commands).map((c) => c.command),
85
93
  }));
86
94
  return res.map(({ error, result }, i) => {
@@ -253,6 +261,15 @@ class Pipeline {
253
261
  writable: true,
254
262
  value: (...args) => this.chain(new mod_js_1.GetBitCommand(args, this.commandOptions))
255
263
  });
264
+ /**
265
+ * @see https://redis.io/commands/getdel
266
+ */
267
+ Object.defineProperty(this, "getdel", {
268
+ enumerable: true,
269
+ configurable: true,
270
+ writable: true,
271
+ value: (...args) => this.chain(new mod_js_1.GetDelCommand(args, this.commandOptions))
272
+ });
256
273
  /**
257
274
  * @see https://redis.io/commands/getrange
258
275
  */
@@ -1014,6 +1031,15 @@ class Pipeline {
1014
1031
  writable: true,
1015
1032
  value: (...args) => this.chain(new mod_js_1.ZLexCountCommand(args, this.commandOptions))
1016
1033
  });
1034
+ /**
1035
+ * @see https://redis.io/commands/zmscore
1036
+ */
1037
+ Object.defineProperty(this, "zmscore", {
1038
+ enumerable: true,
1039
+ configurable: true,
1040
+ writable: true,
1041
+ value: (...args) => this.chain(new zmscore_js_1.ZMScoreCommand(args, this.commandOptions))
1042
+ });
1017
1043
  /**
1018
1044
  * @see https://redis.io/commands/zpopmax
1019
1045
  */
@@ -1122,9 +1148,10 @@ class Pipeline {
1122
1148
  writable: true,
1123
1149
  value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
1124
1150
  });
1125
- this.client = client;
1151
+ this.client = opts.client;
1126
1152
  this.commands = [];
1127
- this.commandOptions = commandOptions;
1153
+ this.commandOptions = opts.commandOptions;
1154
+ this.multiExec = opts.multiExec ?? false;
1128
1155
  }
1129
1156
  /**
1130
1157
  * Pushes a command into the pipelien and returns a chainable instance of the
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Redis = void 0;
4
4
  const mod_js_1 = require("./commands/mod.js");
5
5
  const pipeline_js_1 = require("./pipeline.js");
6
+ const script_js_1 = require("./script.js");
7
+ const zmscore_js_1 = require("./commands/zmscore.js");
6
8
  /**
7
9
  * Serverless redis client for upstash.
8
10
  */
@@ -52,7 +54,30 @@ class Redis {
52
54
  enumerable: true,
53
55
  configurable: true,
54
56
  writable: true,
55
- value: () => new pipeline_js_1.Pipeline(this.client, this.opts)
57
+ value: () => new pipeline_js_1.Pipeline({
58
+ client: this.client,
59
+ commandOptions: this.opts,
60
+ multiExec: false,
61
+ })
62
+ });
63
+ /**
64
+ * Create a new transaction to allow executing multiple steps atomically.
65
+ *
66
+ * All the commands in a transaction are serialized and executed sequentially. A request sent by
67
+ * another client will never be served in the middle of the execution of a Redis Transaction. This
68
+ * guarantees that the commands are executed as a single isolated operation.
69
+ *
70
+ * @see {@link Pipeline}
71
+ */
72
+ Object.defineProperty(this, "multi", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: () => new pipeline_js_1.Pipeline({
77
+ client: this.client,
78
+ commandOptions: this.opts,
79
+ multiExec: true,
80
+ })
56
81
  });
57
82
  /**
58
83
  * @see https://redis.io/commands/append
@@ -216,6 +241,15 @@ class Redis {
216
241
  writable: true,
217
242
  value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
218
243
  });
244
+ /**
245
+ * @see https://redis.io/commands/getdel
246
+ */
247
+ Object.defineProperty(this, "getdel", {
248
+ enumerable: true,
249
+ configurable: true,
250
+ writable: true,
251
+ value: (...args) => new mod_js_1.GetDelCommand(args, this.opts).exec(this.client)
252
+ });
219
253
  /**
220
254
  * @see https://redis.io/commands/getrange
221
255
  */
@@ -977,6 +1011,15 @@ class Redis {
977
1011
  writable: true,
978
1012
  value: (...args) => new mod_js_1.ZLexCountCommand(args, this.opts).exec(this.client)
979
1013
  });
1014
+ /**
1015
+ * @see https://redis.io/commands/zmscore
1016
+ */
1017
+ Object.defineProperty(this, "zmscore", {
1018
+ enumerable: true,
1019
+ configurable: true,
1020
+ writable: true,
1021
+ value: (...args) => new zmscore_js_1.ZMScoreCommand(args, this.opts).exec(this.client)
1022
+ });
980
1023
  /**
981
1024
  * @see https://redis.io/commands/zpopmax
982
1025
  */
@@ -1088,5 +1131,8 @@ class Redis {
1088
1131
  this.client = client;
1089
1132
  this.opts = opts;
1090
1133
  }
1134
+ createScript(script) {
1135
+ return new script_js_1.Script(this, script);
1136
+ }
1091
1137
  }
1092
1138
  exports.Redis = Redis;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Script = void 0;
4
+ const mod_js_1 = require("../deps/deno.land/x/sha1@v1.0.3/mod.js");
5
+ /**
6
+ * Creates a new script.
7
+ *
8
+ * Scripts offer the ability to optimistically try to execute a script without having to send the
9
+ * entire script to the server. If the script is loaded on the server, it tries again by sending
10
+ * the entire script. Afterwards, the script is cached on the server.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const redis = new Redis({...})
15
+ *
16
+ * const script = redis.createScript<string>("return ARGV[1];")
17
+ * const arg1 = await script.eval([], ["Hello World"])
18
+ * assertEquals(arg1, "Hello World")
19
+ * ```
20
+ */
21
+ class Script {
22
+ constructor(redis, script) {
23
+ Object.defineProperty(this, "script", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "sha1", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: void 0
34
+ });
35
+ Object.defineProperty(this, "redis", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: void 0
40
+ });
41
+ this.redis = redis;
42
+ this.sha1 = this.digest(script);
43
+ this.script = script;
44
+ }
45
+ /**
46
+ * Send an `EVAL` command to redis.
47
+ */
48
+ async eval(keys, args) {
49
+ return await this.redis.eval(this.script, keys, args);
50
+ }
51
+ /**
52
+ * Calculates the sha1 hash of the script and then calls `EVALSHA`.
53
+ */
54
+ async evalsha(keys, args) {
55
+ return await this.redis.evalsha(this.sha1, keys, args);
56
+ }
57
+ /**
58
+ * Optimistically try to run `EVALSHA` first.
59
+ * If the script is not loaded in redis, it will fall back and try again with `EVAL`.
60
+ *
61
+ * Following calls will be able to use the cached script
62
+ */
63
+ async exec(keys, args) {
64
+ const res = await this.redis.evalsha(this.sha1, keys, args).catch(async (err) => {
65
+ if (err instanceof Error &&
66
+ err.message.toLowerCase().includes("noscript")) {
67
+ return await this.redis.eval(this.script, keys, args);
68
+ }
69
+ throw err;
70
+ });
71
+ return res;
72
+ }
73
+ /**
74
+ * Compute the sha1 hash of the script and return its hex representation.
75
+ */
76
+ digest(s) {
77
+ const hash = (0, mod_js_1.sha1)(s, "utf8", "hex");
78
+ return typeof hash === "string" ? hash : new TextDecoder().decode(hash);
79
+ }
80
+ }
81
+ exports.Script = Script;
@@ -56,6 +56,7 @@ class Redis extends core.Redis {
56
56
  retry: config.retry,
57
57
  baseUrl: config.url,
58
58
  headers: { authorization: `Bearer ${config.token}` },
59
+ responseEncoding: config.responseEncoding,
59
60
  });
60
61
  super(client, {
61
62
  automaticDeserialization: config.automaticDeserialization,
@@ -58,6 +58,7 @@ class Redis extends core.Redis {
58
58
  retry: config.retry,
59
59
  headers: { authorization: `Bearer ${config.token}` },
60
60
  options: { backend: config.backend },
61
+ responseEncoding: config.responseEncoding,
61
62
  });
62
63
  super(client, {
63
64
  automaticDeserialization: config.automaticDeserialization,
@@ -51,7 +51,8 @@ class Redis extends core.Redis {
51
51
  baseUrl: configOrRequester.url,
52
52
  retry: configOrRequester.retry,
53
53
  headers: { authorization: `Bearer ${configOrRequester.token}` },
54
- // agent: configOrRequester.agent,
54
+ // agent: configOrRequester.agent,
55
+ responseEncoding: configOrRequester.responseEncoding,
55
56
  });
56
57
  super(client, {
57
58
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -50,7 +50,8 @@ class Redis extends core.Redis {
50
50
  baseUrl: configOrRequester.url,
51
51
  retry: configOrRequester.retry,
52
52
  headers: { authorization: `Bearer ${configOrRequester.token}` },
53
- // agent: configOrRequester.agent,
53
+ agent: configOrRequester.agent,
54
+ responseEncoding: configOrRequester.responseEncoding,
54
55
  });
55
56
  super(client, {
56
57
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -0,0 +1,5 @@
1
+ export declare function init(lookup: string[], revLookup: number[], urlsafe?: boolean): {
2
+ byteLength(b64: string): number;
3
+ toUint8Array(b64: string): Uint8Array;
4
+ fromUint8Array(buf: Uint8Array): string;
5
+ };
@@ -0,0 +1 @@
1
+ export declare const byteLength: (b64: string) => number, toUint8Array: (b64: string) => Uint8Array, fromUint8Array: (buf: Uint8Array) => string;
@@ -0,0 +1 @@
1
+ export { encode, decode } from "../../../denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js";
@@ -0,0 +1,26 @@
1
+ /** Byte length of a SHA1 digest. */
2
+ export declare const BYTES: number;
3
+ /** A class representation of the SHA1 algorithm. */
4
+ export declare class SHA1 {
5
+ readonly hashSize: number;
6
+ private _buf;
7
+ private _bufIdx;
8
+ private _count;
9
+ private _K;
10
+ private _H;
11
+ private _finalized;
12
+ /** Creates a SHA1 instance. */
13
+ constructor();
14
+ /** Reduces the four input numbers to a single one. */
15
+ protected static F(t: number, b: number, c: number, d: number): number;
16
+ /** Initializes a hash instance. */
17
+ init(): SHA1;
18
+ /** Updates a hash with additional message data. */
19
+ update(msg: string | Uint8Array, inputEncoding?: string): SHA1;
20
+ /** Finalizes a hash with additional message data. */
21
+ digest(outputEncoding?: string): string | Uint8Array;
22
+ /** Performs one transformation cycle. */
23
+ private transform;
24
+ }
25
+ /** Generates a SHA1 hash of the input data. */
26
+ export declare function sha1(msg: string | Uint8Array, inputEncoding?: string, outputEncoding?: string): string | Uint8Array;
@@ -0,0 +1,3 @@
1
+ /** Decodes a Uint8Array to utf8-, base64-, or hex-encoded string. */
2
+ export declare function decode(buf: Uint8Array, encoding?: string): string;
3
+ export declare function encode(str: string, encoding?: string): Uint8Array;
@@ -0,0 +1,7 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/getdel
4
+ */
5
+ export declare class GetDelCommand<TData = string> extends Command<unknown | null, TData | null> {
6
+ constructor(cmd: [key: string], opts?: CommandOptions<unknown | null, TData | null>);
7
+ }
@@ -19,6 +19,7 @@ export * from "./get.js";
19
19
  export * from "./getbit.js";
20
20
  export * from "./getrange.js";
21
21
  export * from "./getset.js";
22
+ export * from "./getdel.js";
22
23
  export * from "./hdel.js";
23
24
  export * from "./hexists.js";
24
25
  export * from "./hget.js";
@@ -2,6 +2,7 @@ import { Command, CommandOptions } from "./command.js";
2
2
  export declare type ScanCommandOptions = {
3
3
  match?: string;
4
4
  count?: number;
5
+ type?: string;
5
6
  };
6
7
  /**
7
8
  * @see https://redis.io/commands/scan
@@ -1,13 +1,42 @@
1
1
  import { Command, CommandOptions } from "./command.js";
2
- export declare type SetCommandOptions = ({
2
+ export declare type SetCommandOptions = {
3
+ get: boolean;
4
+ } | ({
3
5
  ex: number;
4
6
  px?: never;
7
+ exat?: never;
8
+ pxat?: never;
9
+ keepTtl?: never;
5
10
  } | {
6
11
  ex?: never;
7
12
  px: number;
13
+ exat?: never;
14
+ pxat?: never;
15
+ keepTtl?: never;
8
16
  } | {
9
17
  ex?: never;
10
18
  px?: never;
19
+ exat: number;
20
+ pxat?: never;
21
+ keepTtl?: never;
22
+ } | {
23
+ ex?: never;
24
+ px?: never;
25
+ exat?: never;
26
+ pxat: number;
27
+ keepTtl?: never;
28
+ } | {
29
+ ex?: never;
30
+ px?: never;
31
+ exat?: never;
32
+ pxat?: never;
33
+ keepTtl: true;
34
+ } | {
35
+ ex?: never;
36
+ px?: never;
37
+ exat?: never;
38
+ pxat?: never;
39
+ keepTtl?: never;
11
40
  }) & ({
12
41
  nx: true;
13
42
  xx?: never;
@@ -21,6 +50,6 @@ export declare type SetCommandOptions = ({
21
50
  /**
22
51
  * @see https://redis.io/commands/set
23
52
  */
24
- export declare class SetCommand<TData, TResult = "OK"> extends Command<TResult, TData> {
53
+ export declare class SetCommand<TData, TResult = TData | "OK" | null> extends Command<TResult, TData | "OK" | null> {
25
54
  constructor([key, value, opts]: [key: string, value: TData, opts?: SetCommandOptions], cmdOpts?: CommandOptions<TResult, TData>);
26
55
  }
@@ -0,0 +1,7 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/zmscore
4
+ */
5
+ export declare class ZMScoreCommand<TData> extends Command<string[] | null, number[] | null> {
6
+ constructor(cmd: [key: string, members: TData[]], opts?: CommandOptions<string[] | null, number[] | null>);
7
+ }
@@ -29,20 +29,52 @@ export declare type RetryConfig = false | {
29
29
  */
30
30
  backoff?: (retryCount: number) => number;
31
31
  };
32
- declare type Options = {
32
+ export declare type Options = {
33
33
  backend?: string;
34
34
  };
35
+ export declare type RequesterConfig = {
36
+ /**
37
+ * Configure the retry behaviour in case of network errors
38
+ */
39
+ retry?: RetryConfig;
40
+ /**
41
+ * Due to the nature of dynamic and custom data, it is possible to write data to redis that is not
42
+ * valid json and will therefore cause errors when deserializing. This used to happen very
43
+ * frequently with non-utf8 data, such as emojis.
44
+ *
45
+ * By default we will therefore encode the data as base64 on the server, before sending it to the
46
+ * client. The client will then decode the base64 data and parse it as utf8.
47
+ *
48
+ * For very large entries, this can add a few milliseconds, so if you are sure that your data is
49
+ * valid utf8, you can disable this behaviour by setting this option to false.
50
+ *
51
+ * Here's what the response body looks like:
52
+ *
53
+ * ```json
54
+ * {
55
+ * result?: "base64-encoded",
56
+ * error?: string
57
+ * }
58
+ * ```
59
+ *
60
+ * @default "base64"
61
+ */
62
+ responseEncoding?: false | "base64";
63
+ };
35
64
  export declare type HttpClientConfig = {
36
65
  headers?: Record<string, string>;
37
66
  baseUrl: string;
38
67
  options?: Options;
39
68
  retry?: RetryConfig;
40
- };
69
+ agent?: any;
70
+ } & RequesterConfig;
41
71
  export declare class HttpClient implements Requester {
42
72
  baseUrl: string;
43
73
  headers: Record<string, string>;
44
- readonly options?: {
74
+ readonly options: {
45
75
  backend?: string;
76
+ agent: any;
77
+ responseEncoding?: false | "base64";
46
78
  };
47
79
  readonly retry: {
48
80
  attempts: number;
@@ -51,4 +83,3 @@ export declare class HttpClient implements Requester {
51
83
  constructor(config: HttpClientConfig);
52
84
  request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
53
85
  }
54
- export {};