@upstash/redis 1.2.0 → 1.3.0

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/commands.js CHANGED
@@ -34,6 +34,8 @@ __export(commands_exports, {
34
34
  DecrCommand: () => DecrCommand,
35
35
  DelCommand: () => DelCommand,
36
36
  EchoCommand: () => EchoCommand,
37
+ EvalCommand: () => EvalCommand,
38
+ EvalshaCommand: () => EvalshaCommand,
37
39
  ExistsCommand: () => ExistsCommand,
38
40
  ExpireAtCommand: () => ExpireAtCommand,
39
41
  ExpireCommand: () => ExpireCommand,
@@ -104,6 +106,9 @@ __export(commands_exports, {
104
106
  SUnionCommand: () => SUnionCommand,
105
107
  SUnionStoreCommand: () => SUnionStoreCommand,
106
108
  ScanCommand: () => ScanCommand,
109
+ ScriptExistsCommand: () => ScriptExistsCommand,
110
+ ScriptFlushCommand: () => ScriptFlushCommand,
111
+ ScriptLoadCommand: () => ScriptLoadCommand,
107
112
  SetBitCommand: () => SetBitCommand,
108
113
  SetCommand: () => SetCommand,
109
114
  SetExCommand: () => SetExCommand,
@@ -256,6 +261,20 @@ var EchoCommand = class extends Command {
256
261
  }
257
262
  };
258
263
 
264
+ // pkg/commands/eval.ts
265
+ var EvalCommand = class extends Command {
266
+ constructor(script, keys, args) {
267
+ super(["eval", script, keys.length, ...keys, ...args != null ? args : []]);
268
+ }
269
+ };
270
+
271
+ // pkg/commands/evalsha.ts
272
+ var EvalshaCommand = class extends Command {
273
+ constructor(sha, keys, args) {
274
+ super(["evalsha", sha, keys.length, ...keys, ...args != null ? args : []]);
275
+ }
276
+ };
277
+
259
278
  // pkg/commands/exists.ts
260
279
  var ExistsCommand = class extends Command {
261
280
  constructor(...keys) {
@@ -416,16 +435,18 @@ function deserialize2(fields, result) {
416
435
  }
417
436
  var HMGetCommand = class extends Command {
418
437
  constructor(key, ...fields) {
419
- super(["hmget", key, ...fields], {
420
- deserialize: (result) => deserialize2(fields, result)
421
- });
438
+ super(["hmget", key, ...fields], { deserialize: (result) => deserialize2(fields, result) });
422
439
  }
423
440
  };
424
441
 
425
442
  // pkg/commands/hmset.ts
426
443
  var HMSetCommand = class extends Command {
427
444
  constructor(key, kv) {
428
- super(["hmset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])]);
445
+ super([
446
+ "hmset",
447
+ key,
448
+ ...Object.entries(kv).flatMap(([field, value]) => [field, value])
449
+ ]);
429
450
  }
430
451
  };
431
452
 
@@ -446,7 +467,11 @@ var HScanCommand = class extends Command {
446
467
  // pkg/commands/hset.ts
447
468
  var HSetCommand = class extends Command {
448
469
  constructor(key, kv) {
449
- super(["hset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])]);
470
+ super([
471
+ "hset",
472
+ key,
473
+ ...Object.entries(kv).flatMap(([field, value]) => [field, value])
474
+ ]);
450
475
  }
451
476
  };
452
477
 
@@ -579,7 +604,10 @@ var MGetCommand = class extends Command {
579
604
  // pkg/commands/mset.ts
580
605
  var MSetCommand = class extends Command {
581
606
  constructor(kv) {
582
- super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])]);
607
+ super([
608
+ "mset",
609
+ ...Object.entries(kv).flatMap(([key, value]) => [key, value])
610
+ ]);
583
611
  }
584
612
  };
585
613
 
@@ -713,6 +741,38 @@ var SCardCommand = class extends Command {
713
741
  }
714
742
  };
715
743
 
744
+ // pkg/commands/script_exists.ts
745
+ var ScriptExistsCommand = class extends Command {
746
+ constructor(...hash) {
747
+ super(["script", "exists", ...hash], {
748
+ deserialize: (result) => {
749
+ const parsed = result;
750
+ return parsed.length === 1 ? parsed[0] : parsed;
751
+ }
752
+ });
753
+ }
754
+ };
755
+
756
+ // pkg/commands/script_flush.ts
757
+ var ScriptFlushCommand = class extends Command {
758
+ constructor(opts) {
759
+ const cmd = ["script", "flush"];
760
+ if (opts == null ? void 0 : opts.sync) {
761
+ cmd.push("sync");
762
+ } else if (opts == null ? void 0 : opts.async) {
763
+ cmd.push("async");
764
+ }
765
+ super(cmd);
766
+ }
767
+ };
768
+
769
+ // pkg/commands/script_load.ts
770
+ var ScriptLoadCommand = class extends Command {
771
+ constructor(script) {
772
+ super(["script", "load", script]);
773
+ }
774
+ };
775
+
716
776
  // pkg/commands/sdiff.ts
717
777
  var SDiffCommand = class extends Command {
718
778
  constructor(key, ...keys) {
@@ -1120,6 +1180,8 @@ module.exports = __toCommonJS(commands_exports);
1120
1180
  DecrCommand,
1121
1181
  DelCommand,
1122
1182
  EchoCommand,
1183
+ EvalCommand,
1184
+ EvalshaCommand,
1123
1185
  ExistsCommand,
1124
1186
  ExpireAtCommand,
1125
1187
  ExpireCommand,
@@ -1190,6 +1252,9 @@ module.exports = __toCommonJS(commands_exports);
1190
1252
  SUnionCommand,
1191
1253
  SUnionStoreCommand,
1192
1254
  ScanCommand,
1255
+ ScriptExistsCommand,
1256
+ ScriptFlushCommand,
1257
+ ScriptLoadCommand,
1193
1258
  SetBitCommand,
1194
1259
  SetCommand,
1195
1260
  SetExCommand,
package/commands.mjs CHANGED
@@ -9,6 +9,8 @@ import {
9
9
  DecrCommand,
10
10
  DelCommand,
11
11
  EchoCommand,
12
+ EvalCommand,
13
+ EvalshaCommand,
12
14
  ExistsCommand,
13
15
  ExpireAtCommand,
14
16
  ExpireCommand,
@@ -79,6 +81,9 @@ import {
79
81
  SUnionCommand,
80
82
  SUnionStoreCommand,
81
83
  ScanCommand,
84
+ ScriptExistsCommand,
85
+ ScriptFlushCommand,
86
+ ScriptLoadCommand,
82
87
  SetBitCommand,
83
88
  SetCommand,
84
89
  SetExCommand,
@@ -108,7 +113,7 @@ import {
108
113
  ZScanCommand,
109
114
  ZScoreCommand,
110
115
  ZUnionStoreCommand
111
- } from "./chunk-HZBBCLMC.mjs";
116
+ } from "./chunk-K2UC7PHG.mjs";
112
117
  import "./chunk-7YUZYRJS.mjs";
113
118
  export {
114
119
  AppendCommand,
@@ -121,6 +126,8 @@ export {
121
126
  DecrCommand,
122
127
  DelCommand,
123
128
  EchoCommand,
129
+ EvalCommand,
130
+ EvalshaCommand,
124
131
  ExistsCommand,
125
132
  ExpireAtCommand,
126
133
  ExpireCommand,
@@ -191,6 +198,9 @@ export {
191
198
  SUnionCommand,
192
199
  SUnionStoreCommand,
193
200
  ScanCommand,
201
+ ScriptExistsCommand,
202
+ ScriptFlushCommand,
203
+ ScriptLoadCommand,
194
204
  SetBitCommand,
195
205
  SetCommand,
196
206
  SetExCommand,
package/fastly.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { R as Redis$1 } from './redis-a9efcf58';
1
+ import { R as Redis$1 } from './redis-338577a3';
2
2
  import './http';
3
- import './zunionstore-342168a6';
3
+ import 'https';
4
+ import 'http';
5
+ import './zunionstore-633a2e7a';
4
6
 
5
7
  /**
6
8
  * Connection credentials for upstash redis.
@@ -8,18 +10,18 @@ import './zunionstore-342168a6';
8
10
  */
9
11
  declare type RedisConfigFastly = {
10
12
  /**
11
- * UPSTASH_REDIS_REST_URL
12
- */
13
+ * UPSTASH_REDIS_REST_URL
14
+ */
13
15
  url: string;
14
16
  /**
15
- * UPSTASH_REDIS_REST_TOKEN
16
- */
17
+ * UPSTASH_REDIS_REST_TOKEN
18
+ */
17
19
  token: string;
18
20
  /**
19
- * A Request can be forwarded to any backend defined on your service. Backends
20
- * can be created via the Fastly CLI, API, or web interface, and are
21
- * referenced by name.
22
- */
21
+ * A Request can be forwarded to any backend defined on your service. Backends
22
+ * can be created via the Fastly CLI, API, or web interface, and are
23
+ * referenced by name.
24
+ */
23
25
  backend: string;
24
26
  };
25
27
  /**
@@ -27,17 +29,17 @@ declare type RedisConfigFastly = {
27
29
  */
28
30
  declare class Redis extends Redis$1 {
29
31
  /**
30
- * Create a new redis client
31
- *
32
- * @example
33
- * ```typescript
34
- * const redis = new Redis({
35
- * url: "<UPSTASH_REDIS_REST_URL>",
36
- * token: "<UPSTASH_REDIS_REST_TOKEN>",
37
- * backend: "upstash-db",
38
- * });
39
- * ```
40
- */
32
+ * Create a new redis client
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const redis = new Redis({
37
+ * url: "<UPSTASH_REDIS_REST_URL>",
38
+ * token: "<UPSTASH_REDIS_REST_TOKEN>",
39
+ * backend: "upstash-db",
40
+ * });
41
+ * ```
42
+ */
41
43
  constructor(config: RedisConfigFastly);
42
44
  }
43
45
 
package/fastly.js CHANGED
@@ -53,9 +53,7 @@ var UpstashError = class extends Error {
53
53
  var HttpClient = class {
54
54
  constructor(config) {
55
55
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
56
- this.headers = __spreadValues({
57
- "Content-Type": "application/json"
58
- }, config.headers);
56
+ this.headers = __spreadValues({ "Content-Type": "application/json" }, config.headers);
59
57
  this.options = config.options;
60
58
  }
61
59
  async request(req) {
@@ -190,6 +188,20 @@ var EchoCommand = class extends Command {
190
188
  }
191
189
  };
192
190
 
191
+ // pkg/commands/eval.ts
192
+ var EvalCommand = class extends Command {
193
+ constructor(script, keys, args) {
194
+ super(["eval", script, keys.length, ...keys, ...args != null ? args : []]);
195
+ }
196
+ };
197
+
198
+ // pkg/commands/evalsha.ts
199
+ var EvalshaCommand = class extends Command {
200
+ constructor(sha, keys, args) {
201
+ super(["evalsha", sha, keys.length, ...keys, ...args != null ? args : []]);
202
+ }
203
+ };
204
+
193
205
  // pkg/commands/exists.ts
194
206
  var ExistsCommand = class extends Command {
195
207
  constructor(...keys) {
@@ -350,16 +362,18 @@ function deserialize2(fields, result) {
350
362
  }
351
363
  var HMGetCommand = class extends Command {
352
364
  constructor(key, ...fields) {
353
- super(["hmget", key, ...fields], {
354
- deserialize: (result) => deserialize2(fields, result)
355
- });
365
+ super(["hmget", key, ...fields], { deserialize: (result) => deserialize2(fields, result) });
356
366
  }
357
367
  };
358
368
 
359
369
  // pkg/commands/hmset.ts
360
370
  var HMSetCommand = class extends Command {
361
371
  constructor(key, kv) {
362
- super(["hmset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])]);
372
+ super([
373
+ "hmset",
374
+ key,
375
+ ...Object.entries(kv).flatMap(([field, value]) => [field, value])
376
+ ]);
363
377
  }
364
378
  };
365
379
 
@@ -380,7 +394,11 @@ var HScanCommand = class extends Command {
380
394
  // pkg/commands/hset.ts
381
395
  var HSetCommand = class extends Command {
382
396
  constructor(key, kv) {
383
- super(["hset", key, ...Object.entries(kv).flatMap(([field, value]) => [field, value])]);
397
+ super([
398
+ "hset",
399
+ key,
400
+ ...Object.entries(kv).flatMap(([field, value]) => [field, value])
401
+ ]);
384
402
  }
385
403
  };
386
404
 
@@ -513,7 +531,10 @@ var MGetCommand = class extends Command {
513
531
  // pkg/commands/mset.ts
514
532
  var MSetCommand = class extends Command {
515
533
  constructor(kv) {
516
- super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])]);
534
+ super([
535
+ "mset",
536
+ ...Object.entries(kv).flatMap(([key, value]) => [key, value])
537
+ ]);
517
538
  }
518
539
  };
519
540
 
@@ -647,6 +668,38 @@ var SCardCommand = class extends Command {
647
668
  }
648
669
  };
649
670
 
671
+ // pkg/commands/script_exists.ts
672
+ var ScriptExistsCommand = class extends Command {
673
+ constructor(...hash) {
674
+ super(["script", "exists", ...hash], {
675
+ deserialize: (result) => {
676
+ const parsed = result;
677
+ return parsed.length === 1 ? parsed[0] : parsed;
678
+ }
679
+ });
680
+ }
681
+ };
682
+
683
+ // pkg/commands/script_flush.ts
684
+ var ScriptFlushCommand = class extends Command {
685
+ constructor(opts) {
686
+ const cmd = ["script", "flush"];
687
+ if (opts == null ? void 0 : opts.sync) {
688
+ cmd.push("sync");
689
+ } else if (opts == null ? void 0 : opts.async) {
690
+ cmd.push("async");
691
+ }
692
+ super(cmd);
693
+ }
694
+ };
695
+
696
+ // pkg/commands/script_load.ts
697
+ var ScriptLoadCommand = class extends Command {
698
+ constructor(script) {
699
+ super(["script", "load", script]);
700
+ }
701
+ };
702
+
650
703
  // pkg/commands/sdiff.ts
651
704
  var SDiffCommand = class extends Command {
652
705
  constructor(key, ...keys) {
@@ -1069,6 +1122,8 @@ var Pipeline = class {
1069
1122
  this.decrby = (...args) => this.chain(new DecrByCommand(...args));
1070
1123
  this.del = (...args) => this.chain(new DelCommand(...args));
1071
1124
  this.echo = (...args) => this.chain(new EchoCommand(...args));
1125
+ this.eval = (...args) => this.chain(new EvalCommand(...args));
1126
+ this.evalsha = (...args) => this.chain(new EvalshaCommand(...args));
1072
1127
  this.exists = (...args) => this.chain(new ExistsCommand(...args));
1073
1128
  this.expire = (...args) => this.chain(new ExpireCommand(...args));
1074
1129
  this.expireat = (...args) => this.chain(new ExpireAtCommand(...args));
@@ -1126,6 +1181,9 @@ var Pipeline = class {
1126
1181
  this.sadd = (key, ...members) => this.chain(new SAddCommand(key, ...members));
1127
1182
  this.scan = (...args) => this.chain(new ScanCommand(...args));
1128
1183
  this.scard = (...args) => this.chain(new SCardCommand(...args));
1184
+ this.scriptExists = (...args) => this.chain(new ScriptExistsCommand(...args));
1185
+ this.scriptFlush = (...args) => this.chain(new ScriptFlushCommand(...args));
1186
+ this.scriptLoad = (...args) => this.chain(new ScriptLoadCommand(...args));
1129
1187
  this.sdiff = (...args) => this.chain(new SDiffCommand(...args));
1130
1188
  this.sdiffstore = (...args) => this.chain(new SDiffStoreCommand(...args));
1131
1189
  this.set = (key, value, opts) => this.chain(new SetCommand(key, value, opts));
@@ -1195,6 +1253,8 @@ var Redis = class {
1195
1253
  this.decrby = (...args) => new DecrByCommand(...args).exec(this.client);
1196
1254
  this.del = (...args) => new DelCommand(...args).exec(this.client);
1197
1255
  this.echo = (...args) => new EchoCommand(...args).exec(this.client);
1256
+ this.eval = (...args) => new EvalCommand(...args).exec(this.client);
1257
+ this.evalsha = (...args) => new EvalshaCommand(...args).exec(this.client);
1198
1258
  this.exists = (...args) => new ExistsCommand(...args).exec(this.client);
1199
1259
  this.expire = (...args) => new ExpireCommand(...args).exec(this.client);
1200
1260
  this.expireat = (...args) => new ExpireAtCommand(...args).exec(this.client);
@@ -1252,6 +1312,9 @@ var Redis = class {
1252
1312
  this.sadd = (key, ...members) => new SAddCommand(key, ...members).exec(this.client);
1253
1313
  this.scan = (...args) => new ScanCommand(...args).exec(this.client);
1254
1314
  this.scard = (...args) => new SCardCommand(...args).exec(this.client);
1315
+ this.scriptExists = (...args) => new ScriptExistsCommand(...args).exec(this.client);
1316
+ this.scriptFlush = (...args) => new ScriptFlushCommand(...args).exec(this.client);
1317
+ this.scriptLoad = (...args) => new ScriptLoadCommand(...args).exec(this.client);
1255
1318
  this.sdiff = (...args) => new SDiffCommand(...args).exec(this.client);
1256
1319
  this.sdiffstore = (...args) => new SDiffStoreCommand(...args).exec(this.client);
1257
1320
  this.set = (key, value, opts) => new SetCommand(key, value, opts).exec(this.client);
@@ -1308,9 +1371,7 @@ var Redis2 = class extends Redis {
1308
1371
  constructor(config) {
1309
1372
  const client = new HttpClient({
1310
1373
  baseUrl: config.url,
1311
- headers: {
1312
- authorization: `Bearer ${config.token}`
1313
- },
1374
+ headers: { authorization: `Bearer ${config.token}` },
1314
1375
  options: { backend: config.backend }
1315
1376
  });
1316
1377
  super(client);
package/fastly.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Redis
3
- } from "./chunk-256N7RVN.mjs";
4
- import "./chunk-HZBBCLMC.mjs";
3
+ } from "./chunk-CTSQDNTV.mjs";
4
+ import "./chunk-K2UC7PHG.mjs";
5
5
  import {
6
6
  HttpClient
7
- } from "./chunk-HIDCSH5S.mjs";
7
+ } from "./chunk-5LZNFEHI.mjs";
8
8
  import "./chunk-7YUZYRJS.mjs";
9
9
 
10
10
  // pkg/fastly.ts
@@ -12,9 +12,7 @@ var Redis2 = class extends Redis {
12
12
  constructor(config) {
13
13
  const client = new HttpClient({
14
14
  baseUrl: config.url,
15
- headers: {
16
- authorization: `Bearer ${config.token}`
17
- },
15
+ headers: { authorization: `Bearer ${config.token}` },
18
16
  options: { backend: config.backend }
19
17
  });
20
18
  super(client);
package/http.d.ts CHANGED
@@ -1,29 +1,36 @@
1
- declare type HttpRequest = {
1
+ import https from 'https';
2
+ import http from 'http';
3
+
4
+ declare type UpstashRequest = {
2
5
  path?: string[];
3
6
  /**
4
- * Request body will be serialized to json
5
- */
7
+ * Request body will be serialized to json
8
+ */
6
9
  body?: unknown;
7
10
  };
8
11
  declare type UpstashResponse<TResult> = {
9
12
  result?: TResult;
10
13
  error?: string;
11
14
  };
15
+ interface Requester {
16
+ request: <TResult = unknown>(req: UpstashRequest) => Promise<UpstashResponse<TResult>>;
17
+ }
12
18
  declare type HttpClientConfig = {
13
19
  headers?: Record<string, string>;
14
20
  baseUrl: string;
15
21
  options?: {
16
22
  backend?: string;
23
+ agent?: https.Agent | http.Agent;
17
24
  };
18
25
  };
19
- declare class HttpClient {
26
+ declare class HttpClient implements Requester {
20
27
  baseUrl: string;
21
28
  headers: Record<string, string>;
22
29
  readonly options?: {
23
30
  backend?: string;
24
31
  };
25
32
  constructor(config: HttpClientConfig);
26
- request<TResponse>(req: HttpRequest): Promise<TResponse>;
33
+ request<TResult>(req: UpstashRequest): Promise<UpstashResponse<TResult>>;
27
34
  }
28
35
 
29
- export { HttpClient, HttpClientConfig, HttpRequest, UpstashResponse };
36
+ export { HttpClient, HttpClientConfig, Requester, UpstashRequest, UpstashResponse };
package/http.js CHANGED
@@ -53,9 +53,7 @@ var UpstashError = class extends Error {
53
53
  var HttpClient = class {
54
54
  constructor(config) {
55
55
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
56
- this.headers = __spreadValues({
57
- "Content-Type": "application/json"
58
- }, config.headers);
56
+ this.headers = __spreadValues({ "Content-Type": "application/json" }, config.headers);
59
57
  this.options = config.options;
60
58
  }
61
59
  async request(req) {
package/http.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  HttpClient
3
- } from "./chunk-HIDCSH5S.mjs";
3
+ } from "./chunk-5LZNFEHI.mjs";
4
4
  import "./chunk-7YUZYRJS.mjs";
5
5
  export {
6
6
  HttpClient
package/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export { Redis, RedisConfigNodejs } from './nodejs';
2
- import './redis-a9efcf58';
3
- import './http';
4
- import './zunionstore-342168a6';
2
+ export { Requester, UpstashRequest, UpstashResponse } from './http';
3
+ import './redis-338577a3';
4
+ import './zunionstore-633a2e7a';
5
+ import 'https';
6
+ import 'http';
5
7
 
6
8
  /**
7
9
  * Result of a bad request to upstash