@upstash/redis 0.0.0-ci.ba685120 → 0.0.0-ci.bc3aba1f-20221124

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 (80) hide show
  1. package/README.md +14 -19
  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/hgetall.js +0 -4
  9. package/esm/pkg/commands/hrandfield.js +39 -0
  10. package/esm/pkg/commands/lpos.js +19 -0
  11. package/esm/pkg/commands/mod.js +3 -0
  12. package/esm/pkg/commands/scan.js +3 -0
  13. package/esm/pkg/commands/sdiffstore.js +1 -1
  14. package/esm/pkg/commands/set.js +16 -4
  15. package/esm/pkg/commands/zmscore.js +10 -0
  16. package/esm/pkg/commands/zrange.js +6 -0
  17. package/esm/pkg/http.js +82 -2
  18. package/esm/pkg/pipeline.js +52 -6
  19. package/esm/pkg/redis.js +79 -2
  20. package/esm/pkg/script.js +77 -0
  21. package/esm/platforms/cloudflare.js +10 -2
  22. package/esm/platforms/fastly.js +1 -0
  23. package/esm/platforms/node_with_fetch.js +14 -1
  24. package/esm/platforms/nodejs.js +14 -1
  25. package/esm/version.js +1 -0
  26. package/package.json +1 -39
  27. package/script/deps/deno.land/x/base64@v0.2.1/base.js +104 -0
  28. package/script/deps/deno.land/x/base64@v0.2.1/base64url.js +13 -0
  29. package/script/deps/deno.land/x/sha1@v1.0.3/deps.js +6 -0
  30. package/script/deps/deno.land/x/sha1@v1.0.3/mod.js +196 -0
  31. package/script/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.js +55 -0
  32. package/script/pkg/commands/getdel.js +13 -0
  33. package/script/pkg/commands/hgetall.js +0 -4
  34. package/script/pkg/commands/hrandfield.js +43 -0
  35. package/script/pkg/commands/lpos.js +23 -0
  36. package/script/pkg/commands/mod.js +3 -0
  37. package/script/pkg/commands/scan.js +3 -0
  38. package/script/pkg/commands/sdiffstore.js +1 -1
  39. package/script/pkg/commands/set.js +16 -4
  40. package/script/pkg/commands/zmscore.js +14 -0
  41. package/script/pkg/commands/zrange.js +6 -0
  42. package/script/pkg/http.js +82 -2
  43. package/script/pkg/pipeline.js +51 -5
  44. package/script/pkg/redis.js +78 -1
  45. package/script/pkg/script.js +81 -0
  46. package/script/platforms/cloudflare.js +10 -2
  47. package/script/platforms/fastly.js +1 -0
  48. package/script/platforms/node_with_fetch.js +14 -1
  49. package/script/platforms/nodejs.js +14 -1
  50. package/script/version.js +4 -0
  51. package/types/deps/deno.land/x/base64@v0.2.1/base.d.ts +5 -0
  52. package/types/deps/deno.land/x/base64@v0.2.1/base64url.d.ts +1 -0
  53. package/types/deps/deno.land/x/sha1@v1.0.3/deps.d.ts +1 -0
  54. package/types/deps/deno.land/x/sha1@v1.0.3/mod.d.ts +26 -0
  55. package/types/deps/denopkg.com/chiefbiiko/std-encoding@v1.0.0/mod.d.ts +3 -0
  56. package/types/pkg/commands/bitop.d.ts +0 -1
  57. package/types/pkg/commands/bitpos.d.ts +1 -1
  58. package/types/pkg/commands/getdel.d.ts +7 -0
  59. package/types/pkg/commands/hrandfield.d.ts +9 -0
  60. package/types/pkg/commands/lpop.d.ts +1 -1
  61. package/types/pkg/commands/lpos.d.ts +15 -0
  62. package/types/pkg/commands/mget.d.ts +1 -1
  63. package/types/pkg/commands/mod.d.ts +3 -0
  64. package/types/pkg/commands/rpop.d.ts +2 -2
  65. package/types/pkg/commands/scan.d.ts +1 -0
  66. package/types/pkg/commands/sdiffstore.d.ts +1 -1
  67. package/types/pkg/commands/set.d.ts +31 -2
  68. package/types/pkg/commands/spop.d.ts +2 -2
  69. package/types/pkg/commands/zadd.d.ts +1 -1
  70. package/types/pkg/commands/zmscore.d.ts +7 -0
  71. package/types/pkg/commands/zrange.d.ts +7 -0
  72. package/types/pkg/http.d.ts +52 -4
  73. package/types/pkg/pipeline.d.ts +33 -8
  74. package/types/pkg/redis.d.ts +48 -8
  75. package/types/pkg/script.d.ts +42 -0
  76. package/types/platforms/cloudflare.d.ts +8 -7
  77. package/types/platforms/fastly.d.ts +2 -6
  78. package/types/platforms/node_with_fetch.d.ts +2 -21
  79. package/types/platforms/nodejs.d.ts +3 -6
  80. package/types/version.d.ts +1 -0
@@ -28,9 +28,28 @@ 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 (config.telemetry?.runtime) {
42
+ this.headers["Upstash-Telemetry-Runtime"] = config.telemetry.runtime;
43
+ }
44
+ if (config.telemetry?.platform) {
45
+ this.headers["Upstash-Telemetry-Platform"] = config.telemetry.platform;
46
+ }
47
+ if (config.telemetry?.sdk) {
48
+ this.headers["Upstash-Telemetry-Sdk"] = config.telemetry.sdk;
49
+ }
50
+ if (this.options.responseEncoding === "base64") {
51
+ this.headers["Upstash-Encoding"] = "base64";
52
+ }
34
53
  if (typeof config?.retry === "boolean" && config?.retry === false) {
35
54
  this.retry = {
36
55
  attempts: 1,
@@ -51,6 +70,7 @@ class HttpClient {
51
70
  headers: this.headers,
52
71
  body: JSON.stringify(req.body),
53
72
  keepalive: true,
73
+ agent: this.options?.agent,
54
74
  /**
55
75
  * Fastly specific
56
76
  */
@@ -75,7 +95,67 @@ class HttpClient {
75
95
  if (!res.ok) {
76
96
  throw new error_js_1.UpstashError(body.error);
77
97
  }
98
+ if (this.options?.responseEncoding === "base64") {
99
+ return Array.isArray(body) ? body.map(decode) : decode(body);
100
+ }
78
101
  return body;
79
102
  }
80
103
  }
81
104
  exports.HttpClient = HttpClient;
105
+ function base64decode(b64) {
106
+ let dec = "";
107
+ try {
108
+ /**
109
+ * Using only atob() is not enough because it doesn't work with unicode characters
110
+ */
111
+ const binString = atob(b64);
112
+ const size = binString.length;
113
+ const bytes = new Uint8Array(size);
114
+ for (let i = 0; i < size; i++) {
115
+ bytes[i] = binString.charCodeAt(i);
116
+ }
117
+ dec = new TextDecoder().decode(bytes);
118
+ }
119
+ catch {
120
+ dec = b64;
121
+ }
122
+ try {
123
+ return decodeURIComponent(dec);
124
+ }
125
+ catch {
126
+ return dec;
127
+ }
128
+ }
129
+ function decode(raw) {
130
+ let result = undefined;
131
+ switch (typeof raw.result) {
132
+ case "undefined":
133
+ return raw;
134
+ case "number": {
135
+ result = raw.result;
136
+ break;
137
+ }
138
+ case "object": {
139
+ if (Array.isArray(raw.result)) {
140
+ result = raw.result.map((v) => typeof v === "string"
141
+ ? base64decode(v)
142
+ : Array.isArray(v)
143
+ ? v.map(base64decode)
144
+ : v);
145
+ }
146
+ else {
147
+ // If it's not an array it must be null
148
+ // Apparently null is an object in javascript
149
+ result = null;
150
+ }
151
+ break;
152
+ }
153
+ case "string": {
154
+ result = raw.result === "OK" ? "OK" : base64decode(raw.result);
155
+ break;
156
+ }
157
+ default:
158
+ break;
159
+ }
160
+ return { result, error: raw.error };
161
+ }
@@ -3,6 +3,8 @@ 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");
7
+ const hrandfield_js_1 = require("./commands/hrandfield.js");
6
8
  /**
7
9
  * Upstash REST API supports command pipelining to send multiple commands in
8
10
  * batch, instead of sending each command one by one and waiting for a response.
@@ -19,7 +21,7 @@ const error_js_1 = require("./error.js");
19
21
  * **Examples:**
20
22
  *
21
23
  * ```ts
22
- * const p = redis.pipeline()
24
+ * const p = redis.pipeline() // or redis.multi()
23
25
  * p.set("key","value")
24
26
  * p.get("key")
25
27
  * const res = await p.exec()
@@ -42,7 +44,7 @@ const error_js_1 = require("./error.js");
42
44
  * ```
43
45
  */
44
46
  class Pipeline {
45
- constructor(client, commandOptions) {
47
+ constructor(opts) {
46
48
  Object.defineProperty(this, "client", {
47
49
  enumerable: true,
48
50
  configurable: true,
@@ -61,6 +63,12 @@ class Pipeline {
61
63
  writable: true,
62
64
  value: void 0
63
65
  });
66
+ Object.defineProperty(this, "multiExec", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
64
72
  /**
65
73
  * Send the pipeline request to upstash.
66
74
  *
@@ -79,8 +87,9 @@ class Pipeline {
79
87
  if (this.commands.length === 0) {
80
88
  throw new Error("Pipeline is empty");
81
89
  }
90
+ const path = this.multiExec ? ["multi-exec"] : ["pipeline"];
82
91
  const res = (await this.client.request({
83
- path: ["pipeline"],
92
+ path,
84
93
  body: Object.values(this.commands).map((c) => c.command),
85
94
  }));
86
95
  return res.map(({ error, result }, i) => {
@@ -253,6 +262,15 @@ class Pipeline {
253
262
  writable: true,
254
263
  value: (...args) => this.chain(new mod_js_1.GetBitCommand(args, this.commandOptions))
255
264
  });
265
+ /**
266
+ * @see https://redis.io/commands/getdel
267
+ */
268
+ Object.defineProperty(this, "getdel", {
269
+ enumerable: true,
270
+ configurable: true,
271
+ writable: true,
272
+ value: (...args) => this.chain(new mod_js_1.GetDelCommand(args, this.commandOptions))
273
+ });
256
274
  /**
257
275
  * @see https://redis.io/commands/getrange
258
276
  */
@@ -361,6 +379,15 @@ class Pipeline {
361
379
  writable: true,
362
380
  value: (key, kv) => this.chain(new mod_js_1.HMSetCommand([key, kv], this.commandOptions))
363
381
  });
382
+ /**
383
+ * @see https://redis.io/commands/hrandfield
384
+ */
385
+ Object.defineProperty(this, "hrandfield", {
386
+ enumerable: true,
387
+ configurable: true,
388
+ writable: true,
389
+ value: (key, count, withValues) => this.chain(new hrandfield_js_1.HRandFieldCommand([key, count, withValues], this.commandOptions))
390
+ });
364
391
  /**
365
392
  * @see https://redis.io/commands/hscan
366
393
  */
@@ -478,6 +505,15 @@ class Pipeline {
478
505
  writable: true,
479
506
  value: (...args) => this.chain(new mod_js_1.LPopCommand(args, this.commandOptions))
480
507
  });
508
+ /**
509
+ * @see https://redis.io/commands/lpos
510
+ */
511
+ Object.defineProperty(this, "lpos", {
512
+ enumerable: true,
513
+ configurable: true,
514
+ writable: true,
515
+ value: (...args) => this.chain(new mod_js_1.LPosCommand(args, this.commandOptions))
516
+ });
481
517
  /**
482
518
  * @see https://redis.io/commands/lpush
483
519
  */
@@ -1005,6 +1041,15 @@ class Pipeline {
1005
1041
  writable: true,
1006
1042
  value: (...args) => this.chain(new mod_js_1.ZLexCountCommand(args, this.commandOptions))
1007
1043
  });
1044
+ /**
1045
+ * @see https://redis.io/commands/zmscore
1046
+ */
1047
+ Object.defineProperty(this, "zmscore", {
1048
+ enumerable: true,
1049
+ configurable: true,
1050
+ writable: true,
1051
+ value: (...args) => this.chain(new zmscore_js_1.ZMScoreCommand(args, this.commandOptions))
1052
+ });
1008
1053
  /**
1009
1054
  * @see https://redis.io/commands/zpopmax
1010
1055
  */
@@ -1113,9 +1158,10 @@ class Pipeline {
1113
1158
  writable: true,
1114
1159
  value: (...args) => this.chain(new mod_js_1.ZUnionStoreCommand(args, this.commandOptions))
1115
1160
  });
1116
- this.client = client;
1161
+ this.client = opts.client;
1117
1162
  this.commands = [];
1118
- this.commandOptions = commandOptions;
1163
+ this.commandOptions = opts.commandOptions;
1164
+ this.multiExec = opts.multiExec ?? false;
1119
1165
  }
1120
1166
  /**
1121
1167
  * 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
  */
@@ -31,6 +33,18 @@ class Redis {
31
33
  writable: true,
32
34
  value: void 0
33
35
  });
36
+ /**
37
+ * Wrap a new middleware around the HTTP client.
38
+ */
39
+ Object.defineProperty(this, "use", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: (middleware) => {
44
+ const makeRequest = this.client.request.bind(this.client);
45
+ this.client.request = (req) => middleware(req, makeRequest);
46
+ }
47
+ });
34
48
  /**
35
49
  * Create a new pipeline that allows you to send requests in bulk.
36
50
  *
@@ -40,7 +54,30 @@ class Redis {
40
54
  enumerable: true,
41
55
  configurable: true,
42
56
  writable: true,
43
- 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
+ })
44
81
  });
45
82
  /**
46
83
  * @see https://redis.io/commands/append
@@ -204,6 +241,15 @@ class Redis {
204
241
  writable: true,
205
242
  value: (...args) => new mod_js_1.GetBitCommand(args, this.opts).exec(this.client)
206
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
+ });
207
253
  /**
208
254
  * @see https://redis.io/commands/getrange
209
255
  */
@@ -312,6 +358,16 @@ class Redis {
312
358
  writable: true,
313
359
  value: (key, kv) => new mod_js_1.HMSetCommand([key, kv], this.opts).exec(this.client)
314
360
  });
361
+ /**
362
+ * @see https://redis.io/commands/hrandfield
363
+ */
364
+ Object.defineProperty(this, "hrandfield", {
365
+ enumerable: true,
366
+ configurable: true,
367
+ writable: true,
368
+ value: (key, count, withValues) => new mod_js_1.HRandFieldCommand([key, count, withValues], this.opts)
369
+ .exec(this.client)
370
+ });
315
371
  /**
316
372
  * @see https://redis.io/commands/hscan
317
373
  */
@@ -429,6 +485,15 @@ class Redis {
429
485
  writable: true,
430
486
  value: (...args) => new mod_js_1.LPopCommand(args, this.opts).exec(this.client)
431
487
  });
488
+ /**
489
+ * @see https://redis.io/commands/lpos
490
+ */
491
+ Object.defineProperty(this, "lpos", {
492
+ enumerable: true,
493
+ configurable: true,
494
+ writable: true,
495
+ value: (...args) => new mod_js_1.LPosCommand(args, this.opts).exec(this.client)
496
+ });
432
497
  /**
433
498
  * @see https://redis.io/commands/lpush
434
499
  */
@@ -956,6 +1021,15 @@ class Redis {
956
1021
  writable: true,
957
1022
  value: (...args) => new mod_js_1.ZLexCountCommand(args, this.opts).exec(this.client)
958
1023
  });
1024
+ /**
1025
+ * @see https://redis.io/commands/zmscore
1026
+ */
1027
+ Object.defineProperty(this, "zmscore", {
1028
+ enumerable: true,
1029
+ configurable: true,
1030
+ writable: true,
1031
+ value: (...args) => new zmscore_js_1.ZMScoreCommand(args, this.opts).exec(this.client)
1032
+ });
959
1033
  /**
960
1034
  * @see https://redis.io/commands/zpopmax
961
1035
  */
@@ -1067,5 +1141,8 @@ class Redis {
1067
1141
  this.client = client;
1068
1142
  this.opts = opts;
1069
1143
  }
1144
+ createScript(script) {
1145
+ return new script_js_1.Script(this, script);
1146
+ }
1070
1147
  }
1071
1148
  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;
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Redis = void 0;
27
27
  const core = __importStar(require("../pkg/redis.js"));
28
28
  const http_js_1 = require("../pkg/http.js");
29
+ const version_js_1 = require("../version.js");
29
30
  /**
30
31
  * Serverless redis client for upstash.
31
32
  */
@@ -41,7 +42,7 @@ class Redis extends core.Redis {
41
42
  * });
42
43
  * ```
43
44
  */
44
- constructor(config) {
45
+ constructor(config, env) {
45
46
  if (config.url.startsWith(" ") ||
46
47
  config.url.endsWith(" ") ||
47
48
  /\r|\n/.test(config.url)) {
@@ -52,10 +53,17 @@ class Redis extends core.Redis {
52
53
  /\r|\n/.test(config.token)) {
53
54
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
54
55
  }
56
+ const telemetry = {};
57
+ if (!env?.UPSTASH_DISABLE_TELEMETRY) {
58
+ telemetry.platform = "cloudflare";
59
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
60
+ }
55
61
  const client = new http_js_1.HttpClient({
56
62
  retry: config.retry,
57
63
  baseUrl: config.url,
58
64
  headers: { authorization: `Bearer ${config.token}` },
65
+ responseEncoding: config.responseEncoding,
66
+ telemetry,
59
67
  });
60
68
  super(client, {
61
69
  automaticDeserialization: config.automaticDeserialization,
@@ -83,7 +91,7 @@ class Redis extends core.Redis {
83
91
  if (!token) {
84
92
  throw new Error("Unable to find environment variable: `UPSTASH_REDIS_REST_TOKEN`. Please add it via `wrangler secret put UPSTASH_REDIS_REST_TOKEN`");
85
93
  }
86
- return new Redis({ ...opts, url, token });
94
+ return new Redis({ ...opts, url, token }, env);
87
95
  }
88
96
  }
89
97
  exports.Redis = Redis;
@@ -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,
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Redis = void 0;
28
28
  const core = __importStar(require("../pkg/redis.js"));
29
29
  const http_js_1 = require("../pkg/http.js");
30
+ const version_js_1 = require("../version.js");
30
31
  require("isomorphic-fetch");
31
32
  /**
32
33
  * Serverless redis client for upstash.
@@ -47,11 +48,23 @@ class Redis extends core.Redis {
47
48
  /\r|\n/.test(configOrRequester.token)) {
48
49
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
49
50
  }
51
+ const telemetry = {};
52
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
53
+ telemetry.runtime = `node@${process.version}`;
54
+ telemetry.platform = process.env.VERCEL
55
+ ? "vercel"
56
+ : process.env.AWS_REGION
57
+ ? "aws"
58
+ : "unknown";
59
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
60
+ }
50
61
  const client = new http_js_1.HttpClient({
51
62
  baseUrl: configOrRequester.url,
52
63
  retry: configOrRequester.retry,
53
64
  headers: { authorization: `Bearer ${configOrRequester.token}` },
54
- // agent: configOrRequester.agent,
65
+ // agent: configOrRequester.agent,
66
+ responseEncoding: configOrRequester.responseEncoding,
67
+ telemetry,
55
68
  });
56
69
  super(client, {
57
70
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -27,6 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Redis = void 0;
28
28
  const core = __importStar(require("../pkg/redis.js"));
29
29
  const http_js_1 = require("../pkg/http.js");
30
+ const version_js_1 = require("../version.js");
30
31
  /**
31
32
  * Serverless redis client for upstash.
32
33
  */
@@ -46,11 +47,23 @@ class Redis extends core.Redis {
46
47
  /\r|\n/.test(configOrRequester.token)) {
47
48
  console.warn("The redis token contains whitespace or newline, which can cause errors!");
48
49
  }
50
+ const telemetry = {};
51
+ if (!process.env.UPSTASH_DISABLE_TELEMETRY) {
52
+ telemetry.runtime = `node@${process.version}`;
53
+ telemetry.platform = process.env.VERCEL
54
+ ? "vercel"
55
+ : process.env.AWS_REGION
56
+ ? "aws"
57
+ : "unknown";
58
+ telemetry.sdk = `@upstash/redis@${version_js_1.VERSION}`;
59
+ }
49
60
  const client = new http_js_1.HttpClient({
50
61
  baseUrl: configOrRequester.url,
51
62
  retry: configOrRequester.retry,
52
63
  headers: { authorization: `Bearer ${configOrRequester.token}` },
53
- // agent: configOrRequester.agent,
64
+ agent: configOrRequester.agent,
65
+ responseEncoding: configOrRequester.responseEncoding,
66
+ telemetry,
54
67
  });
55
68
  super(client, {
56
69
  automaticDeserialization: configOrRequester.automaticDeserialization,
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VERSION = void 0;
4
+ exports.VERSION = "v0.0.0-ci.bc3aba1f-20221124";
@@ -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;
@@ -6,7 +6,6 @@ export declare class BitOpCommand extends Command<number, number> {
6
6
  constructor(cmd: [
7
7
  op: "and" | "or" | "xor",
8
8
  destinationKey: string,
9
- sourceKey: string,
10
9
  ...sourceKeys: string[]
11
10
  ], opts?: CommandOptions<number, number>);
12
11
  constructor(cmd: [op: "not", destinationKey: string, sourceKey: string], opts?: CommandOptions<number, number>);
@@ -3,5 +3,5 @@ import { Command, CommandOptions } from "./command.js";
3
3
  * @see https://redis.io/commands/bitpos
4
4
  */
5
5
  export declare class BitPosCommand extends Command<number, number> {
6
- constructor(cmd: [key: string, start: number, end: number], opts?: CommandOptions<number, number>);
6
+ constructor(cmd: [key: string, bit: 0 | 1, start?: number, end?: number], opts?: CommandOptions<number, number>);
7
7
  }
@@ -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
+ }
@@ -0,0 +1,9 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/hrandfield
4
+ */
5
+ export declare class HRandFieldCommand<TData extends string | string[] | Record<string, unknown>> extends Command<string | string[], TData> {
6
+ constructor(cmd: [key: string], opts?: CommandOptions<string, string>);
7
+ constructor(cmd: [key: string, count: number], opts?: CommandOptions<string[], string[]>);
8
+ constructor(cmd: [key: string, count: number, withValues: boolean], opts?: CommandOptions<string[], Partial<TData>>);
9
+ }
@@ -3,5 +3,5 @@ import { Command, CommandOptions } from "./command.js";
3
3
  * @see https://redis.io/commands/lpop
4
4
  */
5
5
  export declare class LPopCommand<TData = string> extends Command<unknown | null, TData | null> {
6
- constructor(cmd: [key: string], opts?: CommandOptions<unknown | null, TData | null>);
6
+ constructor(cmd: [key: string, count?: number], opts?: CommandOptions<unknown | null, TData | null>);
7
7
  }
@@ -0,0 +1,15 @@
1
+ import { Command, CommandOptions } from "./command.js";
2
+ /**
3
+ * @see https://redis.io/commands/lpos
4
+ */
5
+ export declare class LPosCommand<TData = number> extends Command<TData, TData> {
6
+ constructor(cmd: [
7
+ key: string,
8
+ element: unknown,
9
+ opts?: {
10
+ rank?: number;
11
+ count?: number;
12
+ maxLen?: number;
13
+ }
14
+ ], opts?: CommandOptions<TData, TData>);
15
+ }