@upstash/redis 1.3.0-alpha.0 → 1.3.1

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
@@ -35,6 +35,7 @@ __export(commands_exports, {
35
35
  DelCommand: () => DelCommand,
36
36
  EchoCommand: () => EchoCommand,
37
37
  EvalCommand: () => EvalCommand,
38
+ EvalshaCommand: () => EvalshaCommand,
38
39
  ExistsCommand: () => ExistsCommand,
39
40
  ExpireAtCommand: () => ExpireAtCommand,
40
41
  ExpireCommand: () => ExpireCommand,
@@ -105,6 +106,9 @@ __export(commands_exports, {
105
106
  SUnionCommand: () => SUnionCommand,
106
107
  SUnionStoreCommand: () => SUnionStoreCommand,
107
108
  ScanCommand: () => ScanCommand,
109
+ ScriptExistsCommand: () => ScriptExistsCommand,
110
+ ScriptFlushCommand: () => ScriptFlushCommand,
111
+ ScriptLoadCommand: () => ScriptLoadCommand,
108
112
  SetBitCommand: () => SetBitCommand,
109
113
  SetCommand: () => SetCommand,
110
114
  SetExCommand: () => SetExCommand,
@@ -259,8 +263,15 @@ var EchoCommand = class extends Command {
259
263
 
260
264
  // pkg/commands/eval.ts
261
265
  var EvalCommand = class extends Command {
262
- constructor(script, nArgs, ...args) {
263
- super(["eval", script, nArgs, ...args]);
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 : []]);
264
275
  }
265
276
  };
266
277
 
@@ -424,16 +435,18 @@ function deserialize2(fields, result) {
424
435
  }
425
436
  var HMGetCommand = class extends Command {
426
437
  constructor(key, ...fields) {
427
- super(["hmget", key, ...fields], {
428
- deserialize: (result) => deserialize2(fields, result)
429
- });
438
+ super(["hmget", key, ...fields], { deserialize: (result) => deserialize2(fields, result) });
430
439
  }
431
440
  };
432
441
 
433
442
  // pkg/commands/hmset.ts
434
443
  var HMSetCommand = class extends Command {
435
444
  constructor(key, kv) {
436
- 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
+ ]);
437
450
  }
438
451
  };
439
452
 
@@ -454,7 +467,11 @@ var HScanCommand = class extends Command {
454
467
  // pkg/commands/hset.ts
455
468
  var HSetCommand = class extends Command {
456
469
  constructor(key, kv) {
457
- 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
+ ]);
458
475
  }
459
476
  };
460
477
 
@@ -587,7 +604,10 @@ var MGetCommand = class extends Command {
587
604
  // pkg/commands/mset.ts
588
605
  var MSetCommand = class extends Command {
589
606
  constructor(kv) {
590
- super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])]);
607
+ super([
608
+ "mset",
609
+ ...Object.entries(kv).flatMap(([key, value]) => [key, value])
610
+ ]);
591
611
  }
592
612
  };
593
613
 
@@ -721,6 +741,38 @@ var SCardCommand = class extends Command {
721
741
  }
722
742
  };
723
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
+
724
776
  // pkg/commands/sdiff.ts
725
777
  var SDiffCommand = class extends Command {
726
778
  constructor(key, ...keys) {
@@ -1129,6 +1181,7 @@ module.exports = __toCommonJS(commands_exports);
1129
1181
  DelCommand,
1130
1182
  EchoCommand,
1131
1183
  EvalCommand,
1184
+ EvalshaCommand,
1132
1185
  ExistsCommand,
1133
1186
  ExpireAtCommand,
1134
1187
  ExpireCommand,
@@ -1199,6 +1252,9 @@ module.exports = __toCommonJS(commands_exports);
1199
1252
  SUnionCommand,
1200
1253
  SUnionStoreCommand,
1201
1254
  ScanCommand,
1255
+ ScriptExistsCommand,
1256
+ ScriptFlushCommand,
1257
+ ScriptLoadCommand,
1202
1258
  SetBitCommand,
1203
1259
  SetCommand,
1204
1260
  SetExCommand,
package/commands.mjs CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  DelCommand,
11
11
  EchoCommand,
12
12
  EvalCommand,
13
+ EvalshaCommand,
13
14
  ExistsCommand,
14
15
  ExpireAtCommand,
15
16
  ExpireCommand,
@@ -80,6 +81,9 @@ import {
80
81
  SUnionCommand,
81
82
  SUnionStoreCommand,
82
83
  ScanCommand,
84
+ ScriptExistsCommand,
85
+ ScriptFlushCommand,
86
+ ScriptLoadCommand,
83
87
  SetBitCommand,
84
88
  SetCommand,
85
89
  SetExCommand,
@@ -109,7 +113,7 @@ import {
109
113
  ZScanCommand,
110
114
  ZScoreCommand,
111
115
  ZUnionStoreCommand
112
- } from "./chunk-TLMWNHIZ.mjs";
116
+ } from "./chunk-K2UC7PHG.mjs";
113
117
  import "./chunk-7YUZYRJS.mjs";
114
118
  export {
115
119
  AppendCommand,
@@ -123,6 +127,7 @@ export {
123
127
  DelCommand,
124
128
  EchoCommand,
125
129
  EvalCommand,
130
+ EvalshaCommand,
126
131
  ExistsCommand,
127
132
  ExpireAtCommand,
128
133
  ExpireCommand,
@@ -193,6 +198,9 @@ export {
193
198
  SUnionCommand,
194
199
  SUnionStoreCommand,
195
200
  ScanCommand,
201
+ ScriptExistsCommand,
202
+ ScriptFlushCommand,
203
+ ScriptLoadCommand,
196
204
  SetBitCommand,
197
205
  SetCommand,
198
206
  SetExCommand,
package/fastly.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { R as Redis$1 } from './redis-5b966c20';
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) {
@@ -192,8 +190,15 @@ var EchoCommand = class extends Command {
192
190
 
193
191
  // pkg/commands/eval.ts
194
192
  var EvalCommand = class extends Command {
195
- constructor(script, nArgs, ...args) {
196
- super(["eval", script, nArgs, ...args]);
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 : []]);
197
202
  }
198
203
  };
199
204
 
@@ -357,16 +362,18 @@ function deserialize2(fields, result) {
357
362
  }
358
363
  var HMGetCommand = class extends Command {
359
364
  constructor(key, ...fields) {
360
- super(["hmget", key, ...fields], {
361
- deserialize: (result) => deserialize2(fields, result)
362
- });
365
+ super(["hmget", key, ...fields], { deserialize: (result) => deserialize2(fields, result) });
363
366
  }
364
367
  };
365
368
 
366
369
  // pkg/commands/hmset.ts
367
370
  var HMSetCommand = class extends Command {
368
371
  constructor(key, kv) {
369
- 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
+ ]);
370
377
  }
371
378
  };
372
379
 
@@ -387,7 +394,11 @@ var HScanCommand = class extends Command {
387
394
  // pkg/commands/hset.ts
388
395
  var HSetCommand = class extends Command {
389
396
  constructor(key, kv) {
390
- 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
+ ]);
391
402
  }
392
403
  };
393
404
 
@@ -520,7 +531,10 @@ var MGetCommand = class extends Command {
520
531
  // pkg/commands/mset.ts
521
532
  var MSetCommand = class extends Command {
522
533
  constructor(kv) {
523
- super(["mset", ...Object.entries(kv).flatMap(([key, value]) => [key, value])]);
534
+ super([
535
+ "mset",
536
+ ...Object.entries(kv).flatMap(([key, value]) => [key, value])
537
+ ]);
524
538
  }
525
539
  };
526
540
 
@@ -654,6 +668,38 @@ var SCardCommand = class extends Command {
654
668
  }
655
669
  };
656
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
+
657
703
  // pkg/commands/sdiff.ts
658
704
  var SDiffCommand = class extends Command {
659
705
  constructor(key, ...keys) {
@@ -1077,6 +1123,7 @@ var Pipeline = class {
1077
1123
  this.del = (...args) => this.chain(new DelCommand(...args));
1078
1124
  this.echo = (...args) => this.chain(new EchoCommand(...args));
1079
1125
  this.eval = (...args) => this.chain(new EvalCommand(...args));
1126
+ this.evalsha = (...args) => this.chain(new EvalshaCommand(...args));
1080
1127
  this.exists = (...args) => this.chain(new ExistsCommand(...args));
1081
1128
  this.expire = (...args) => this.chain(new ExpireCommand(...args));
1082
1129
  this.expireat = (...args) => this.chain(new ExpireAtCommand(...args));
@@ -1134,6 +1181,9 @@ var Pipeline = class {
1134
1181
  this.sadd = (key, ...members) => this.chain(new SAddCommand(key, ...members));
1135
1182
  this.scan = (...args) => this.chain(new ScanCommand(...args));
1136
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));
1137
1187
  this.sdiff = (...args) => this.chain(new SDiffCommand(...args));
1138
1188
  this.sdiffstore = (...args) => this.chain(new SDiffStoreCommand(...args));
1139
1189
  this.set = (key, value, opts) => this.chain(new SetCommand(key, value, opts));
@@ -1204,6 +1254,7 @@ var Redis = class {
1204
1254
  this.del = (...args) => new DelCommand(...args).exec(this.client);
1205
1255
  this.echo = (...args) => new EchoCommand(...args).exec(this.client);
1206
1256
  this.eval = (...args) => new EvalCommand(...args).exec(this.client);
1257
+ this.evalsha = (...args) => new EvalshaCommand(...args).exec(this.client);
1207
1258
  this.exists = (...args) => new ExistsCommand(...args).exec(this.client);
1208
1259
  this.expire = (...args) => new ExpireCommand(...args).exec(this.client);
1209
1260
  this.expireat = (...args) => new ExpireAtCommand(...args).exec(this.client);
@@ -1261,6 +1312,9 @@ var Redis = class {
1261
1312
  this.sadd = (key, ...members) => new SAddCommand(key, ...members).exec(this.client);
1262
1313
  this.scan = (...args) => new ScanCommand(...args).exec(this.client);
1263
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);
1264
1318
  this.sdiff = (...args) => new SDiffCommand(...args).exec(this.client);
1265
1319
  this.sdiffstore = (...args) => new SDiffStoreCommand(...args).exec(this.client);
1266
1320
  this.set = (key, value, opts) => new SetCommand(key, value, opts).exec(this.client);
@@ -1317,9 +1371,7 @@ var Redis2 = class extends Redis {
1317
1371
  constructor(config) {
1318
1372
  const client = new HttpClient({
1319
1373
  baseUrl: config.url,
1320
- headers: {
1321
- authorization: `Bearer ${config.token}`
1322
- },
1374
+ headers: { authorization: `Bearer ${config.token}` },
1323
1375
  options: { backend: config.backend }
1324
1376
  });
1325
1377
  super(client);
package/fastly.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  Redis
3
- } from "./chunk-CWZSFQQQ.mjs";
4
- import "./chunk-TLMWNHIZ.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-5b966c20';
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